Facebook ログインエラー:CSRF が検出されました

Hi!

My users cannot log in with Facebook anymore. This is the error log:

(facebook) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected

I’m using Cloudflare in front of nginx. I’m using Cloudflare automatic SSL (flexible). I didn’t install any certificate on my server (i.e. I’m not using Letsencrypt).

Is this related to Cloudflare? Can this be solved without installing Letsencrypt?

Thanks!

このエラーは Google と Facebook の両方で同様のものです。私の設定には nginx に次の行がありました。

# proxy_set_header X-Forwarded-Proto $https;

これを以下に変更しました。

proxy_set_header X-Forwarded-Proto $scheme;

するとエラーが解消しました。

このトピックを読んで解決策を見つけました: Redirect URI mismatch in Google Auth

回答を改善する必要があります。

FBとGoogle認証を試した後、会社のポリシーによりOffice365ログインに落ち着きました。

ディスコースサーバーをプロキシの後ろに移動したところ(下の画像を参照)、O365認証が利用できなくなりました。force httpsを有効にする必要がありましたが、プロキシの後ろではこのオプションが機能しませんでした。幸い、Danielによって解決されました: https://meta.discourse.org/t/moved-site-behind-proxy-favicon-and-header-not-using-https-anymore/131486/11。

内部Nginx設定の行

proxy_set_header X-Forwarded-Proto $scheme;

は以下に置き換える必要があります

proxy_set_header X-Forwarded-Proto "https";

外部Nginxはこの種の変更は必要ありません。以下の設定になっています:

proxy_set_header X-Forwarded-Proto $scheme;

おそらく、FB、Google、その他の種類の認証でも同様でしょう。

追伸

明らかにその文字列にはタイプミス$が含まれており、無意味でした。