Skip to content

feat: Shibbolethログイン用スクリプトをlogin.phpからlogin.pyに置き換え - #1944

Open
mhaya wants to merge 1 commit into
fix/63224from
feature/jgss_login_py
Open

mhaya wants to merge 1 commit into
fix/63224from
feature/jgss_login_py

Conversation

@mhaya

@mhaya mhaya commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

概要

nginx の Shibboleth ログイン用スクリプト login.php を、upstream(main)の nginx/login.py をベースにした login.py に置き換えます。

main の login.py は fastcgi のパラメータ名(Shib-Session-ID, eppn など)をそのまま POST し、それに対応するバックエンド側の変更(Shib-Session-ID 受け取り、attribute_mapping 設定)を前提としています。本ブランチのバックエンドは SHIB_ATTR_* 形式を受け付けるため、login.py は login.php と同じ SHIB_ATTR_* 形式で送るよう調整しています。バックエンドの変更はありません。

変更内容

  • nginx/login.py を追加、nginx/login.php を削除
  • nginx/Dockerfile: php-fpm / php-curl を fcgiwrap / python3-requests に置き換え、PHP 用の設定(sed)を削除
  • nginx/supervisord.conf: php-fpm を fcgiwrap(www-data, /tmp/fcgiwrap.sock)に置き換え
  • nginx/weko.conf: /secure の転送先を fcgiwrap に変更し、/secure/login.py/<path> 形式に対応するため fastcgi_split_path_info を追加
  • WEKO_ACCOUNTS_SHIB_IDP_LOGIN_URL を secure/login.py に変更(config.py, scripts/instance.cfg)

upstream の login.py との差分

  • ステータス行は CGI 標準の Status: 302 Found を使用
  • next を URL エンコード、エラー時の JavaScript 内 URL をエスケープ
  • 未使用の一時 cookie ファイルを作成しない
  • ベース URL は login.php と同じく SERVER_NAME を使用

テスト

  • スタブのバックエンドに対して login.py を実行し、login.php と同じ 5 項目(SHIB_ATTR_USER_NAME, SHIB_ATTR_EPPN, SHIB_ATTR_MAIL, SHIB_ATTR_SESSION_ID, SHIB_ATTR_ROLE_AUTHORITY_NAME)を POST し、返された URL へ 302 することを確認
  • HTTP_WEKOSOCIETYAFFILIATION がない場合に "Permission is invalid" のアラートを返すことを確認
  • nginx イメージのビルド
  • ステージング環境での実際の Shibboleth ログイン

注意

/secure で PHP を使うのは login.php だけだったため、イメージから PHP を削除しています。

🤖 Generated with Claude Code

Summary by Sourcery

Replace the PHP-based Shibboleth login proxy with a Python CGI implementation and update nginx and application configuration to use it.

New Features:

  • Replace the Shibboleth login proxy with a Python CGI script that forwards the existing backend attribute format and handles authentication redirects.

Bug Fixes:

  • Preserve safe redirect behavior by encoding destination URLs and escaping error-page redirects.

Enhancements:

  • Switch the nginx secure endpoint from PHP-FPM to fcgiwrap for Python CGI execution and remove the PHP runtime dependencies.
  • Update Shibboleth login configuration to use the new Python endpoint.

Build:

  • Replace PHP packages and configuration with fcgiwrap and Python Requests in the nginx image.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f395cab-c512-4514-975e-6884861a0103

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR migrates the nginx Shibboleth login proxy from PHP-FPM to a Python CGI script served by fcgiwrap, preserving the existing SHIB_ATTR_* backend payload while updating routing, container dependencies, supervision, and login endpoint configuration. Basic script behavior was tested, but nginx image-build and staging Shibboleth-login validation remain outstanding.

Sequence diagram for the Python Shibboleth login proxy

sequenceDiagram
    participant Browser
    participant Nginx
    participant LoginPy as login.py
    participant Backend as WEKO backend

    Browser->>Nginx: GET /secure/login.py?next=...
    Nginx->>LoginPy: Execute via fcgiwrap
    LoginPy->>LoginPy: Check HTTP_WEKOSOCIETYAFFILIATION
    LoginPy->>Backend: POST /weko/shib/login with SHIB_ATTR_* fields
    Backend-->>LoginPy: Redirect path or login page
    alt redirect path
        LoginPy-->>Nginx: Status: 302 Found and Location
        Nginx-->>Browser: 302 redirect
    else login page
        LoginPy-->>Nginx: Status: 200 OK and HTML
        Nginx-->>Browser: Login page
    end
Loading

File-Level Changes

Change Details Files
Replace the PHP Shibboleth login proxy with a Python CGI script while preserving the backend’s existing attribute contract.
  • Add a Python CGI handler that validates affiliation, posts the five SHIB_ATTR_* fields to the backend, and emits CGI redirects or HTML responses.
  • Encode the next URL and safely serialize the error-page redirect URL; retain SERVER_NAME-based URL construction.
  • Remove the PHP login script and update the configured IdP login endpoint to login.py.
nginx/login.py
nginx/login.php
modules/weko-accounts/weko_accounts/config.py
scripts/instance.cfg
Reconfigure the nginx container and process supervision to execute the Python CGI script through fcgiwrap instead of PHP-FPM.
  • Replace PHP packages with fcgiwrap and python3-requests, install and expose the executable login.py, and remove PHP-FPM configuration edits.
  • Run fcgiwrap on /tmp/fcgiwrap.sock under www-data.
  • Route /secure requests through fcgiwrap and split login.py path information for FastCGI execution.
nginx/Dockerfile
nginx/supervisord.conf
nginx/weko.conf

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@mhaya
mhaya changed the base branch from feature/jgss_202609 to fix/63224 October 23, 2026 06:13

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 security issue, and 1 other issue

Security issues:

  • Certificate verification has been explicitly disabled. This permits insecure connections to insecure servers. Re-enable certification validation. (link)

Fixed security issues:

  • SSL verification is disabled but should not be (currently CURLOPT_SSL_VERIFYPEER= false) (link)
Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="nginx/login.py" line_range="39" />
<code_context>
+    }
+
+    # Request to the Shibboleth login
+    response = requests.post(url, data=data, verify=False)
+    response.raise_for_status()
+    redirect = response.text
</code_context>
<issue_to_address>
**Backend TLS can be impersonated**

When traffic between nginx and the backend is intercepted, `requests.post(..., verify=False)` accepts an untrusted certificate, letting the interceptor read or alter the identity attributes and session ID and affect the login response; users can be impersonated or receive attacker-controlled content.

Enable certificate verification and configure the trusted CA for the backend.
</issue_to_address>

### Comment 2
<location path="nginx/login.py" line_range="39" />
<code_context>
    response = requests.post(url, data=data, verify=False)
</code_context>
<issue_to_address>
**security (python.requests.security.disabled-cert-validation):** Certificate verification has been explicitly disabled. This permits insecure connections to insecure servers. Re-enable certification validation.

*Source: opengrep*
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and the new login proxy posts Shibboleth identity and affiliation attributes with TLS certificate verification disabled, so an interceptor could read them or alter the login response. Reverting restores the previous login path, but any attributes disclosed or access granted while this is live cannot be undone.

Blocking findings: nginx/login.py:39, nginx/login.py:39


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread nginx/login.py
}

# Request to the Shibboleth login
response = requests.post(url, data=data, verify=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Backend TLS can be impersonated

When traffic between nginx and the backend is intercepted, requests.post(..., verify=False) accepts an untrusted certificate, letting the interceptor read or alter the identity attributes and session ID and affect the login response; users can be impersonated or receive attacker-controlled content.

Enable certificate verification and configure the trusted CA for the backend.

Prompt for AI agents
In `nginx/login.py` at line 39:

**Backend TLS can be impersonated**

When traffic between nginx and the backend is intercepted, `requests.post(..., verify=False)` accepts an untrusted certificate, letting the interceptor read or alter the identity attributes and session ID and affect the login response; users can be impersonated or receive attacker-controlled content.

Enable certificate verification and configure the trusted CA for the backend.

Comment thread nginx/login.py
}

# Request to the Shibboleth login
response = requests.post(url, data=data, verify=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (python.requests.security.disabled-cert-validation): Certificate verification has been explicitly disabled. This permits insecure connections to insecure servers. Re-enable certification validation.

Source: opengrep

upstream (RCOSDP/weko main) の nginx/login.py をベースに、現行バックエンドの
/weko/shib/login が受け付ける SHIB_ATTR_* 形式のフォームデータを送るよう調整した。

- nginx/login.py を追加し、nginx/login.php を削除
- php-fpm を廃止し fcgiwrap + python3-requests で /secure を実行
- /secure/login.py/<path> 形式に対応するため fastcgi_split_path_info を追加
- WEKO_ACCOUNTS_SHIB_IDP_LOGIN_URL を secure/login.py に変更

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant