0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Seafile】Cloudflare Tunnel経由で「CSRF検証に失敗したため...」と出てログインできない時の対処法 (Docker)

Posted at

状況

ファイル管理ソフト「Seafile」をCloudflare Tunnelを使って外部公開し,ログインしようとしたところ,ログイン画面までは表示されるものの,ID・パスワードを入れて送信すると以下のエラーが出て弾かれた.

CSRF検証に失敗したため、リクエストは中断されました。 

環境

  • サーバー: Raspberry Pi 5(Ubuntu Server24.0.4 LTS)
  • デプロイ方法: Docker Compose
  • Seafileバージョン: 11.0(Docker公式イメージ)
  • 公開方法: Cloudflare Tunnel
  • 構成:
    • Internet (HTTPS) -> Cloudflare Tunnel -> Seafile Container (HTTP)

原因

SeafileのWebインターフェース(Seahub)はPythonのフレームワーク「Django」で作られています. 最近のバージョン(Seafile 11系 / Django 4系)ではセキュリティが強化され,リバースプロキシ経由でアクセスする場合,設定ファイルで明示的に「信頼できるオリジン(ドメイン)」を指定しないと,CSRF攻撃とみなされてブロックされる仕様になっているそうです.

特にCloudflare Tunnelなどのリバースプロキシを通すと,外部からのhttpsアクセスが,内部ではhttp通信として処理されるため,オリジンの不一致が起きやすいようです.

Seafileの構成要素については公式のページがありました.

解決方法

手順1: 設定ファイルを開く

Dockerのボリュームマウント先(例:/mnt/nas/seafile-storage/seafile/conf/など)にあるseahub_settings.pyを開きます.

sudo vim /mnt/nas/seafile/conf/seahub_settings.py

手順2: 設定を追記・修正する

以下の2点をおこないます.

  • SERVICE_URLをhttpsに修正(もしhttpになっていたら)
  • 末尾にCSRF_TRUSTED_ORIGINSを追記

# 外部公開URLと一致させる
SERVICE_URL = "https://nas.example.com"

# ... (既存の設定) ...

# 追記
CSRF_TRUSTED_ORIGINS = ["https://nas.example.com"]

手順3: 再起動

設定を反映させるためにコンテナを再起動します.

これで無事にログインできるようになりました.

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?