Skip to content

fix: ファイルの取得・プレビュー・IIIF でファイル単位の権限判定を行う - #1925

Merged
ivis-miyachi merged 7 commits into
develop_v2.1.0from
fix/file-access-permission
Sep 29, 2026
Merged

ivis-miyachi merged 7 commits into
develop_v2.1.0from
fix/file-access-permission

Conversation

@mhaya

@mhaya mhaya commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

概要 (Summary)

  • weko-records-ui: ファイル権限の判定(check_file_download_permission / is_owners_or_superusers)で、Community Administrator を自コミュニティ配下のアイテムに限る(has_comadmin_permission)。System / Repository Administrator は従来どおり
  • weko-records-ui: プレビュー(preview)に、ファイル単位の権限を要求するデコレータ file_permission_required を付ける
  • invenio-iiif: 画像配信(protect_api)で、対象ファイルが属するレコードの閲覧権限とファイルの権限を判定する。マニフェストに page_permission_factory を適用し、列挙する画像も権限のあるものに絞る。サムネイル作成タスク(内部処理)は利用者の権限を確かめずに対象を解決する
  • invenio-files-rest: ゲストトークンでのファイル操作を、そのトークンのゲストアクティビティに紐づくバケットに限る
  • 背景: ファイル本体を返す経路の一部で、ファイル単位の権限判定が行われていない、または不十分だった
  • 挙動の変化: Community Administrator は自コミュニティ配下に無いアイテムの制限ファイルを取得・プレビューできなくなる / プレビューで権限のないファイルは未ログインならログイン画面、ログイン済みなら 403 / IIIF の画像・info.json は権限がなければ 404(存在しないオブジェクトも 404。従来は 500)/ IIIF のマニフェストは閲覧できないレコードなら 401・403 / ゲストは自分のアクティビティ以外のバケットのファイルを操作できなくなる

関連Issue / チケット (Related Issues)

  • 非公開(API 台帳とチケットで管理。docs/RULE.md §1 により、番号と修正内容をここで結び付けない)

変更タイプ (Type of Change)

  • 🚀 新機能追加 (Feature)
  • 🐛 バグ修正 (Bug Fix)
  • 🔒 セキュリティ修正 (Security Fix)
  • 🚫 機能のクローズ・非公開化・削除 (Feature Deprecation/Disable)
  • ⚠️ 破壊的変更・データ移行を伴う修正 (Breaking Change / Migration)
  • 📚 仕様書・マニュアル・APIリストの更新 (Documentation)

🤖 0. CI 自動チェック (API Inventory Drift)

PR ごとに WEKO3 コンテナを起動し、url_map のダンプ・台帳との突き合わせ・変更行の
到達可否測定を自動実行する。結果は PR コメントと Actions の artifact
(api-inventory-summary) に出る。

このリポジトリは public のため、台帳もベースラインも同梱していない。
実データはプライベートリポジトリ RCOSDP/weko-secret にあり、CI は Secret 経由で取得する。
以降この文書では、そこを単にプライベートリポジトリと呼ぶ。

台帳はブランチごとに内容が違うため、CI は weko 側と同名のブランチを
プライベートリポジトリから探して使う(head → base → 既定ブランチ の順)。
採用されたブランチ名は PR コメントの冒頭に出るので、件数を読む前にそこを見ること。
対応ブランチが無い場合は既定ブランチと比較され、コメント冒頭に警告が出る。
その件数は当てにならないので、PASS でも「確認済み」と読まないこと。
詳細: tools/api-inventory/ci/README.md §3a

  • CI が PASS している、または FAIL の各項目に対処済み
    • Unit Tests は PASS。API Inventory Drift は PR 作成後に実行中(結果を見て更新する)
      Secret (API_INVENTORY_REPO / API_INVENTORY_SSH_KEY) が未設定のリポジトリ、
      および fork からの PR では、このジョブは何もせずスキップされる。

API を追加・変更した場合(必須)

  • プライベートリポジトリ側の作業ブランチを、この PR のブランチと同名で切った
    • 未作成。経路の追加・削除は無いが、認可の変化を台帳に反映するため、この PR と同名で作成する
      この PR が fix/issue62569 → develop_v2.0.4 なら、プライベート側も
      fix/issue62569 → develop_v2.0.4。同名にしておけば台帳 PR が未マージでも
      CI がそれを見るので、2つの PR のマージ順を気にしなくてよい。
  • プライベートリポジトリの api_snapshot.json を更新し、対応する PR を出した
    • 経路の追加・削除は無い。Drift の結果(認可デコレータの差分)を見て更新する
      export WEKO_API_INVENTORY_DIR=/path/to/weko-secret
      ./install.sh
      python3 tools/api-inventory/scripts/snapshot.py --out "$WEKO_API_INVENTORY_DIR/api_snapshot.json"
      更新しないと CI が落ちる。公開リポジトリのコード変更とは別の PRになる。
  • プライベートリポジトリの weko3_api_list_full.tsv に行を追加・更新し、
    • 行の追加は無い。該当行の所見・対応状況はプライベートリポジトリ側で更新する
      build_checklist.py で 24 列版を再生成した(未収載だと reconcile が FAIL する)
  • 台帳・スナップショット・実測結果をこの公開リポジトリにコミットしていない
    (git status に *.tsv / api_snapshot.json が出ていないこと)

FAIL したときの対処(要約)

まず PR コメント冒頭の台帳ブランチを見る。警告が出ていれば、件数を追う前に
プライベートリポジトリ側の対応ブランチを用意すること(比較相手が違うので件数に意味がない)。

ジョブが落ちる条件は 3 つある。PR コメントのどのセクションに件数が出ているかで切り分ける。

落ちた場所 落ちる条件
ベースラインとの差分 (drift.md) G1〜G7 のいずれかに該当
台帳との突き合わせ (reconcile.md) A + B + C + D + E の合計が 1 件以上
変更行の到達可否測定 (probe) G8 / G9 に該当(結果は artifact に含めないので Actions のログで件数を見る)
検出 意味 対処
G1 / G2 新規経路に認証系デコレータが無い / 認証系デコレータが削除された 実装を直す。意図的な公開なら台帳に根拠を書いてベースライン更新
G3 認証・認可デコレータのコメントアウトが増えた 原則やり直し。残す場合は理由をコード中のコメントに明記する
G4 *_PERMISSION_FACTORY / CSRF 保護 等が危険側の値に変わった 原則やり直し
G5 ModelView の can_delete / can_export が False → True 意図的なら台帳の data_op を更新
G6 静的解析で属性が取れない経路が追加された 台帳に行を追加してレビューする(外部ライブラリ由来など)
G7 依存パッケージの更新で経路が増減した 増えた経路は台帳に追加。消えた経路は行を削除するか allow に登録
G8 台帳で data_op が作成/更新/削除の経路に、未認証で到達した 原則やり直し。意図的な公開なら台帳の根拠を更新。data_op の記載誤りなら台帳を直す
G9 台帳では遮断なのに実測で到達(認可の回帰) 原則やり直し
reconcile A / E 実機にあるが台帳に無い(A: URI 単位 / E: 同一 URI の endpoint 単位) 台帳に行を追加する
reconcile B 台帳にあるが実機の url_map に無い 理由を確認し、正当なら allow に登録する
reconcile C / D メソッド・app 列の記載誤り 台帳を実機に合わせる

reconcile B のうち、実機に存在しないことが正当な行(プラグイン未登録・config で無効等)は
プライベートリポジトリの reconcile_allow.json に理由付きで登録する。理由なしの登録は不可。
登録済みの行は B'(既知・許容)として集計され、E'(endpoint が実機に無い)と併せてゲート対象外になる。

W1〜W6 は WARN でゲートは通るが、レビューでは見ること
(ModelView の追加 / 実装本体の変化 / HTTP メソッド・URL の変化 / 監視対象 config の変化 /
依存パッケージの版の変化)。特に W6(依存の版)は、ベースラインを CI と異なる環境で作ると
毎回出続けて形骸化するため、ベースラインは install.sh で作った環境から生成する。

CI の出力は件数のみ。該当した経路名は Actions には出ないので、プライベートリポジトリ側の
完全版レポート(--summary-only なしで再実行したもの)で確認すること
(このリポジトリは public で、ログ・artifact・PR コメントは誰でも読めるため)。


🔒 1. セキュリティ & API アクセス制御チェック (必須)

認証・認可 (Authentication & Authorization)

  • 新規/変更された Blueprint・View・REST リソースに適切なデコレータ / Permission を設定している
    • 例: @login_required, @pass_record, need(...), Invenio Access Action
    • /api/* では Permission.require(http_exception=403) を使うこと。
      @login_required は API アプリに security.login が無いため 401 ではなく 500 になる
    • CI: G1 / G2 が自動検出(デコレータの有無・削除)
  • 状態変更・破壊的メソッド (POST / PUT / PATCH / DELETE) の権限が正しく制限されている
    • CI: G8 が変更行を未認証で実測(使い捨て環境なので --allow-writes 付きで
      GET / HEAD 以外も叩く)
  • 未ログイン(Anonymous)状態でアクセスした際、意図しないデータ取得・変更が拒絶される
    • CI: G8 / G9 が変更行を実測。ただし測定対象は変更行のみ、かつ既定プロファイルで
      起動した経路のみ。ワークフロー系など未解決プレースホルダの行は skip される
  • 認可を config の permission factory に委ねている場合、None で無効化していない
    • CI: G4 が *_PERMISSION_FACTORY 等を監視

機能クローズ・非公開化の場合 (Feature Disable)

  • UI(画面・ボタン)の非表示だけでなく、バックエンド API(ルーティング・View)も完全に遮断されている
  • 無効化状態で直接 API を叩いた場合、404 Not Found または 403 Forbidden が返ることを確認した

🧪 2. テストコード観点チェック (pytest / Invenio Test Suite)

権限・異常系テスト (Negative & Authorization Tests)

  • 未認証アクセス (Anonymous): トークン/セッションなしのリクエストで 401 Unauthorized または 403 Forbidden / 404 Not Found が返ることを検証するテストがある
  • 権限不足ユーザー (Forbidden): 閲覧権限のみのユーザーが更新/削除 API を叩いた際に 403 になるテストがある
  • 無効化/非公開機能の遮断テスト: 対象機能が無効化されている場合、エンドポイントが 404 / 403 を返すテストがある

境界値・入力バリデーションテスト (Boundary & Validation)

  • 不正なパラメータ(巨大ファイル、異常な MIME タイプ、無効な JSON/XML スキーマ、SQLi/XSS ペイロード等)で適切に 400 Bad Request / バリデーションエラーが返るテストがある

データ整合性・トランザクションテスト (Integrity & Rollback)

  • ファイルストレージ(S3/ローカル)書き込み失敗時や DB エラー時に、中途半端なレコードやゴミファイルが残らずロールバックされるテストがある

🛡️ 3. データ保護 & 破壊的変更防止チェック (Data Safety)

  • 物理削除・上書きの安全性:
    • ファイル・アイテム・メタデータの完全削除/置換処理に、意図しない一括削除や別レコードへの誤適用リスクがない
    • 論理削除、バージョン管理、バックアップ等のロールバック機構が考慮されている
  • トランザクション整合性:
    • DB 更新とストレージ操作がアトミックに管理されている

⚙️ 4. マイグレーション & システム影響チェック (Invenio / WEKO3 Stack)

データベース (DB / Alembic)

  • invenio alembic upgrade(適用)および downgrade(ロールバック)スクリプトを作成・検証した
    • 該当なし(DB の変更なし)
  • 既存データに対する破壊的変更(カラム削除、型変更、NOT NULL 制約追加等)の移行スクリプト/データパッチを用意した

検索インデックス (Elasticsearch / OpenSearch)

  • マッピング定義変更の有無を確認した
    • 確認済み。マッピングの変更なし
  • インデックス再作成(Reindex)やエイリアス切り替え手順を準備・検証した

設定 & 非同期処理 (Config / Celery / Cache)

  • invenio.cfg / 環境変数のデフォルト値を設定した
  • Celery タスクのシグネチャ変更によるキュー滞留・不整合が発生しない
  • キャッシュ(Redis/Memcached)のパージが必要か確認した

📚 5. ドキュメント・仕様書更新チェック (weko-document)

  • API インベントリ: ツールは本リポジトリの tools/api-inventory/、
    台帳・調査記録はプライベートリポジトリ(public リポジトリには置かない)。
    §0 のチェック項目で対応済みなら、ここは確認のみ。
    • エンドポイントの追加・変更・廃止、メソッド、認証・認可要件、リクエスト/レスポンス仕様を更新した
    • 調査記録(weko3_api_auth_findings.md)もプライベートリポジトリに置く。台帳は二重管理しない
  • WEKO3 機能仕様書:
    • 対象機能の仕様追加・変更・クローズ(非公開化)内容を反映した
  • 各種マニュアル (管理者 / 利用者マニュアル):
    • 画面導線・操作手順・権限仕様の変更を反映した
  • 更新不要な場合(理由): API の仕様(経路・パラメータ・応答形式)は変わらない。認可の変化は API 台帳(プライベートリポジトリ)で更新する

📋 6. 動作検証エビデンス (Verification Evidence)

テスト実行結果

weko-records-ui     test_permissions.py / test_fd.py / test_preview.py  80件 (78 passed, 既存の xfail 1)
invenio-iiif        tests 全34件 passed
invenio-files-rest  追加したテスト passed
GitHub Actions Unit Tests  success

CI の成果物 (artifact: api-inventory-summary)

ファイル 内容
drift.md ベースラインとの差分(件数のみ)
reconcile.md 台帳と実機の突き合わせ(件数のみ)

明細(該当した経路名・実測結果)は公開できないため artifact に含めていない。
プライベートリポジトリ側で同じコマンドを --summary-only なしで実行して確認する。

手動で確認したこと

  • 未確認(レビュー時に確認をお願いしたい点):
    • ワークフローの承認中など、インデックスにまだ入っていない下書きのファイルを、Community Administrator が取得できるか(has_comadmin_permission はインデックスの無いレコードに False を返す)
    • ゲストの利用申請フローを実機で通したときに、ファイルのアップロード・表示が従来どおりできるか

🤖 Generated with Claude Code

mhaya and others added 7 commits September 28, 2026 10:30
ファイルのダウンロード可否と所有者・管理者判定で、Community Administrator
を check_created_id と同じく has_comadmin_permission により自コミュニティ
配下のアイテムに限定する。System / Repository Administrator は従来どおり。

判定を is_superuser_or_record_comadmin にまとめ、
check_file_download_permission と is_owners_or_superusers から使う。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ファイル単位の権限を要求するデコレータ file_permission_required を追加し、
preview に付ける。判定は file_ui と同じく file_permission_factory を使う。
権限がない場合、未ログインならログイン画面へ誘導し、ログイン済みなら 403 を返す。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ゲストトークンを持つセッションに許可するファイル操作を、トークンに対応する
ゲストアクティビティのアイテム(およびそのルートバージョン)に紐づくバケットに
限定する。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IIIF の画像・画像情報の取得時に、対象ファイルが属するレコードの閲覧権限と
ファイルのダウンロード権限を weko-records-ui の既存判定で確認する。
レコードのファイルでないオブジェクトは Invenio-Files-REST の権限で判定する。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
マニフェストのエンドポイントに weko-records-ui のレコード閲覧権限を
permission factory として設定し、マニフェストに含める画像も
ファイルの権限があるものに限定する。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
権限判定はファイル実体の JSON にある accessrole を見る。アイテム登録時は
メタデータがそこへ書き込まれるが、テストのフィクスチャは書き込んでいない
ため、判定が常に許可になりテストが成立していなかった。登録時と同じく
メタデータを書き込んでから判定させる。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
画像を開く処理に権限判定を入れたため、リクエストの外で動くサムネイル作成
タスクが、利用者の情報が無く失敗するようになっていた。内部処理なので対象の
オブジェクトを直接解決し、画像を開く処理にはそれを使わせる。利用者の
リクエストで通る経路の判定は変えない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Sep 29, 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

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: d7d221da-9642-41df-96d9-ce820cc3fcbe

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

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 Sep 29, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR closes file-content authorization gaps by adding file-specific checks to preview and IIIF delivery, scoping Community Administrator privileges to their communities, filtering unauthorized IIIF manifest images, and binding guest-token operations to activity-owned buckets; accompanying tests cover the new permission branches and HTTP behavior.

Sequence diagram for file-authorized IIIF delivery

sequenceDiagram
    participant Client
    participant IIIF as IIIF API
    participant RecordPermission as page_permission_factory
    participant FilePermission as check_file_download_permission
    participant ObjectStore as ObjectVersion

    Client->>IIIF: Request manifest
    IIIF->>RecordPermission: permission_factory(record).can()
    alt Record view denied
        IIIF-->>Client: 401 or 403
    else Record view allowed
        IIIF->>FilePermission: iiif_object_permission_factory(obj, record).can()
        FilePermission->>ObjectStore: ObjectVersion.get(bucket, key, version_id)
        alt File permission denied
            IIIF-->>Client: Manifest excludes image
        else File permission allowed
            IIIF-->>Client: Manifest with authorized images
        end
    end

    Client->>IIIF: Request image or info.json
    IIIF->>ObjectStore: ObjectVersion.get(bucket, key, version_id)
    IIIF->>FilePermission: iiif_object_permission_factory(obj).can()
    alt Object missing or permission denied
        IIIF-->>Client: 404
    else Permission allowed
        IIIF-->>Client: Image or info.json
    end
Loading

Flow diagram for guest-token bucket authorization

flowchart TD
    A[Guest file operation] --> B[get_guest_activity_bucket_ids]
    B --> C[Resolve GuestActivity from guest_token]
    C --> D[Resolve WorkActivity item]
    D --> E[Find item and root-version buckets]
    E --> F{Requested bucket in activity buckets?}
    F -->|Yes| G[Allow file operation]
    F -->|No| H[Deny file operation]
Loading

File-Level Changes

Change Details Files
Constrain file access for Community Administrators to records in their own communities while preserving broader System and Repository Administrator access.
  • Centralize administrator checks and apply community scoping to download and ownership-related permission paths.
  • Add coverage for in-community, out-of-community, and elevated administrator cases.
modules/weko-records-ui/weko_records_ui/permissions.py
modules/weko-records-ui/tests/test_permissions.py
Enforce file-level authorization in preview endpoints using the requested filename.
  • Resolve the requested file through the previewer and check its file metadata before invoking the view.
  • Redirect anonymous users to login and return 403 for authenticated users lacking permission.
modules/weko-records-ui/weko_records_ui/permissions.py
modules/weko-records-ui/weko_records_ui/preview.py
modules/weko-records-ui/tests/test_preview.py
Add record- and file-level authorization throughout IIIF image delivery and manifests.
  • Resolve IIIF objects and require both record visibility and file download permission for record-linked files.
  • Return 404 for unauthorized or missing image objects and 401/403 for unauthorized manifests based on authentication state.
  • Filter manifest canvases to permitted previewable images and configure the recid permission factory.
  • Bypass request-user authorization when resolving objects for internal thumbnail generation.
modules/invenio-iiif/invenio_iiif/permissions.py
modules/invenio-iiif/invenio_iiif/handlers.py
modules/invenio-iiif/invenio_iiif/manifest.py
modules/invenio-iiif/invenio_iiif/views.py
modules/invenio-iiif/invenio_iiif/config.py
modules/invenio-iiif/invenio_iiif/tasks.py
modules/invenio-iiif/tests/test_permissions.py
modules/invenio-iiif/tests/test_handlers.py
modules/invenio-iiif/tests/test_manifest.py
modules/invenio-iiif/tests/test_views.py
Restrict guest-token file operations to buckets associated with the token's workflow activity.
  • Derive allowed buckets from the activity item and its root record version.
  • Validate guest file actions against the derived bucket set and cover allowed, denied, and missing-token cases.
modules/invenio-files-rest/invenio_files_rest/permissions.py
modules/invenio-files-rest/invenio_files_rest/views.py
modules/invenio-files-rest/tests/test_permissions.py
modules/invenio-files-rest/tests/test_views_objectversion.py

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

@github-actions

Copy link
Copy Markdown

🔍 Claude レビュー統合

Claude の追加指摘 3 件 — 🔴 高 0 / 🟠 中 1 / 🟡 低 2

# 出所 箇所 指摘 判定 修正案
1 Claude modules/invenio-files-rest/invenio_files_rest/permissions.py:180 item_id が未設定のゲストアクティビティでは、ゲストのファイル操作が全て拒否される可能性がある 🟠 追加指摘(中) あり
2 Claude modules/invenio-iiif/invenio_iiif/tasks.py:25 create_thumbnail で対象が見つからないと不明瞭な AttributeError になる 🟡 追加指摘(低) あり
3 Claude modules/invenio-iiif/invenio_iiif/tasks.py:24 サムネイル作成タスクで対象が見つからないと g.obj が None になり、後段で AttributeError になる 🟡 追加指摘(低) あり

1. 🟠 [中] item_id が未設定のゲストアクティビティでは、ゲストのファイル操作が全て拒否される可能性がある(Claude の追加指摘)

modules/invenio-files-rest/invenio_files_rest/permissions.py:180 (1/2 パス)

`get_guest_activity_bucket_idsはactivity.item_id が空だと空集合を返す。そのため、item_id` がまだ紐づいていないアクティビティでは、ゲストのアップロードや読み取りが 404 になり、従来の挙動から後退する恐れがある。

修正案

ゲストのアップロードは item_id の確定前に行われるか確認する。行われる場合は、アクティビティに紐づくバケット(workflow が作成したもの)も許可対象に含める。

根拠
if not activity or not activity.item_id:
        return set()

確認: permissions.py:160-198、views.py:376-400 を確認した。weko_workflow/views.py:786 と 1016 は、item_id が無い場合を分岐で扱っている。つまり item_id が空の状態はあり得る。ただし、ゲストアクティビティのどの時点で item_id が入るかまでは確認できていない。


2. 🟡 [低] create_thumbnail で対象が見つからないと不明瞭な AttributeError になる(Claude の追加指摘)

modules/invenio-iiif/invenio_iiif/tasks.py:25 (1/2 パス)

ObjectVersion.get が None を返すと g.obj = None になります。image_opener は hasattr(g, 'obj') だけを見て obj.file を呼ぶため、AttributeError で落ちます。また g が前のタスクの obj を残したままだと、別の画像を誤って処理するおそれがあります。

修正案

obj が None ならタスクを早期 return し、g.obj は使用後に削除する(または image_opener に obj を明示的に渡す)。

根拠
g.obj = ObjectVersion.get(bucket, key, version_id=version_id)

確認: tasks.py の差分と handlers.py:45-56 の image_opener を確認しました。


3. 🟡 [低] サムネイル作成タスクで対象が見つからないと g.obj が None になり、後段で AttributeError になる(Claude の追加指摘)

modules/invenio-iiif/invenio_iiif/tasks.py:24 (1/2 パス)

`ObjectVersion.getは対象が無いと None を返す。それがそのままg.obj に入ると、image_openerがobj.file にアクセスして AttributeError で落ちる。あわせて、hasattr(g, 'obj') が真になるため、protect_api` による権限チェックも経由しない。

修正案

obj が None のときは g.obj を設定せずに return するか、明示的にログを出して終了する。

根拠
g.obj = ObjectVersion.get(bucket, key, version_id=version_id)

確認: tasks.py の差分と handlers.py:45-56 を確認した。


次にすること: 既存レビューは自動化ボットの状態通知だけで、裁定すべき指摘はありませんでした。認可まわりの変更(ゲストトークンのバケット限定、IIIF の権限判定、comadmin のスコープ限定)は、実コードで矛盾を確認できませんでした。create_thumbnail で対象が None の場合の扱いだけ補ってください。


モデル sonnet / 2 回実行して和集合 / コスト $0.4212。同じ入力でも結果が揺れるため複数回まわし、一部のパスでしか挙がらなかったものには回数を添えています

他レビューを踏まえた自動レビューです。誤りが含まれることがあります。

@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 reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. This changes authorization decisions for guest file access, previews, and IIIF retrieval, so a flawed bucket or record/file permission check could expose protected files broadly from the moment it ships. Reverting would stop future access but would not undo files or images already disclosed.


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

@github-actions

Copy link
Copy Markdown

API インベントリ差分(件数のみ)

台帳ブランチ: develop_v2.1.0

明細は公開できないため件数のみ表示しています。該当箇所はプライベートリポジトリ側の台帳・レポートで確認してください。

ベースラインとの差分

API インベントリ差分レポート

  • 旧: b572c442d v2.0.4-577-gb572c442d (profile=default) endpoints=933 (外部ライブラリ由来 359)
  • 新: 232a5a634 v2.0.4-616-g232a5a634 (profile=default) endpoints=933 (外部ライブラリ由来 359)

判定: ✅ PASS (FAIL 0 / WARN 1)

サマリ

分類 件数
ADDED 0
REMOVED 0
RULE_CHANGED 0
METHODS_CHANGED 0
AUTH_CHANGED 0
IMPL_CHANGED 1
ATTRS_UNKNOWN_NEW 0
ModelView 追加 0
ModelView 削除 0
ModelView フラグ変化 0
config 変化 0
コメントアウト認証の増加 0
依存パッケージの版変化 0

[WARN] W2 実装本体が変化(data_op / 情報露出を再確認) — 1件

件数のみ。該当の経路名はプライベートリポジトリ側の完全版レポートを参照。


台帳との突き合わせ

スナップショット ↔ インベントリ 突き合わせ

  • リビジョン: 232a5a634 v2.0.4-616-g232a5a634 経路URI=913
  • 台帳: 行=1053 URI=924

件数のみ。詳細はプライベートリポジトリ側の完全版レポートを参照。

判定: ✅ 一致 (0件)

検出 件数
A. インベントリ未収載(抽出漏れ) 0
B. 実機に無い(未説明) 0
B'. 実機に無い(既知・許容) 11
C. メソッド不一致 0
D. app列の不一致 0
E. endpoint 未収載 0
E'. endpoint が実機に無い(参考) 1

ソース由来の経路検知

ソース由来の経路検知

  • 解析対象: /home/runner/work/weko/weko
検知源 件数
route 286
expose 206
add_url_rule 75
rest_config 28
modelview 23
entry_point 115
計 733

判定: ✅ 全検知が台帳に対応 (0件)

検知源 検知 台帳に対応 未収載 既知・許容
route 286 286 0 0
expose 206 206 0 0
add_url_rule 75 71 0 0
rest_config 28 26 0 2
modelview 23 23 0 0
entry_point 115 115 0 0

add_url_rule(**rule) 形式の config 駆動一括登録が 4 箇所。個々の経路は rest_config 側で検知する。

参考: 静的検知と結びつかなかった台帳行

  • 全体: 170 / 1053 行
  • うち実ファイルを持つ行: 24(pip・framework・ModelView 総称表記を除いた数)

return False


def get_guest_activity_bucket_ids(token):

@ivis-miyachi ivis-miyachi Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.460, 25, 474, 475, 476

if need.method == 'action' and \
need.value in guest_access_file_actions:
return True
if bucket_ids is None:

@ivis-miyachi ivis-miyachi Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.460, 25, 474, 475, 476

"recid": {
"pid_type": "recid",
"route": "/records/<pid_value>",
"permission_factory_imp":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.34, 925, 35

# skip Invenio-Files-REST permission factory
g.obj = ObjectVersion.get(bucket, key, version_id=version_id)
#g.obj = ObjectResource.get_object(bucket, key, version_id)
obj = ObjectVersion.get(bucket, key, version_id=version_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.34, 925, 35

obj
for obj in ObjectVersion.get_by_bucket(bucket).all()
if can_preview(PreviewFile(None, None, obj))
and iiif_object_permission_factory(obj, record=self.record).can()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.35

@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.34, 925, 35

@shared_task(ignore_result=True)
def create_thumbnail(uuid, thumbnail_width):
"""Create the thumbnail for an image."""
# 利用者のリクエストではない内部処理なので、利用者の権限は確かめずに

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.34, 925, 35

abort(500)

# TODO Check permissions
if permission_factory and not permission_factory(record).can():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.35

return type('FileDownLoadPermissionChecker', (), {'can': can})()


def file_permission_required(f):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.459,460

from .permissions import file_permission_required


@file_permission_required

@ivis-miyachi ivis-miyachi Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.459, 466

if role.name in super_users:
is_ok = True
break
is_ok = is_superuser_or_record_comadmin(record)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.459,460

for role in list(current_user.roles or []):
if role.name in supers:
return is_can
if is_superuser_or_record_comadmin(record):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.459,460

for role in list(current_user.roles or []):
if role.name in supers:
return True
return is_superuser_or_record_comadmin(record)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.459,460

return is_superuser_or_record_comadmin(record)


def is_superuser_or_record_comadmin(record) -> bool:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fix no.459,460

@ivis-miyachi
ivis-miyachi merged commit b37cad1 into develop_v2.1.0 Sep 29, 2026
189 checks passed
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.

2 participants