Skip to content

ci: fix security issue on comment.yml#1466

Merged
Marukome0743 merged 1 commit intoOpenUp-LabTakizawa:mainfrom
Marukome0743:pr1466
Apr 9, 2026
Merged

ci: fix security issue on comment.yml#1466
Marukome0743 merged 1 commit intoOpenUp-LabTakizawa:mainfrom
Marukome0743:pr1466

Conversation

@Marukome0743
Copy link
Copy Markdown
Member

@Marukome0743 Marukome0743 commented Apr 9, 2026

Summary by Sourcery

GitHub Actions のワークフローを改善し、環境変数ではなくチェックアウトされたファイルから直接入力を読み取って PR コメントを投稿するようにするとともに、Bun のロックファイルの状態を更新します。

Bug Fixes:

  • コメントと PR 番号を構築する際に、信頼されていない環境変数の補間を避けることで、PR コメント用ワークフローにおける潜在的なセキュリティ問題を修正。

Build:

  • Bun のロックファイルと、mise prepare-state の設定で追跡しているハッシュを更新。

CI:

  • 事前に設定された環境変数ではなくファイル読み込みを用いて、github-script ステップ内で PR 番号とコメント本文を計算するように、コメント用ワークフローを更新。
Original summary in English

Summary by Sourcery

Improve the GitHub Actions workflow that posts PR comments by reading inputs directly from checked-out files instead of environment variables and refresh the Bun lockfile state.

Bug Fixes:

  • Fix potential security issue in the PR comment workflow by avoiding untrusted environment variable interpolation when constructing the comment and PR number.

Build:

  • Refresh Bun lockfile and its tracked hash in the mise prepare-state configuration.

CI:

  • Update the comment workflow to compute the PR number and comment body within the github-script step using file reads rather than pre-populated environment variables.

@github-actions github-actions bot added dependencies Pull requests that update a dependency file 🪸git Modify .gitattributes and .gitignore ♻️ci Changes to CI configuration files and scripts 🧰infrastructure Improvements of facility such as linter etc labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

🪄 Deploy Preview for ready!

Open in Codeflow
Learn more about StackBlitz Codeflow.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

@Marukome0743 is attempting to deploy a commit to the OpenUp Lab Takizawa Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA 7896cea.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 9, 2026

レビュー担当者向けガイド(小さい PR では折りたたみ)

レビュー担当者向けガイド

GitHub Actions のコメント用ワークフローをリファクタリングし、環境変数ではなく github-script ステップ内のファイルから PR 番号とコメント本文を直接読み込むようにすることで、安全でない環境変数の補間を排除し、あわせて Bun の lock/prepare-state メタデータを更新します。

更新された PR コメント用 GitHub Actions ワークフローのシーケンス図

sequenceDiagram
    participant GitHubActions
    participant CommentWorkflow
    participant GithubScriptStep
    participant FileSystem
    participant GitHubAPI

    GitHubActions->>CommentWorkflow: Trigger on workflow_run
    CommentWorkflow->>GithubScriptStep: Run actions/github-script

    GithubScriptStep->>FileSystem: readFile pr_number/pr_number.txt
    FileSystem-->>GithubScriptStep: prNumber (digits only)
    GithubScriptStep->>FileSystem: readFile comment/comment.txt
    FileSystem-->>GithubScriptStep: comment body text

    GithubScriptStep->>GitHubAPI: issues.listComments(owner, repo, prNumber)
    GitHubAPI-->>GithubScriptStep: existing PR comments

    GithubScriptStep->>GithubScriptStep: find existing bot comment matching WORKFLOW_NAME
    GithubScriptStep->>GithubScriptStep: determine shouldComment using CONCLUSION and oldComment
    alt shouldComment is false
        GithubScriptStep-->>CommentWorkflow: exit without commenting
    else shouldComment is true
        alt oldComment exists
            GithubScriptStep->>GitHubAPI: issues.updateComment(commentId, new body)
            GitHubAPI-->>GithubScriptStep: updated comment
        else no oldComment
            GithubScriptStep->>GitHubAPI: issues.createComment(prNumber, comment)
            GitHubAPI-->>GithubScriptStep: created comment
        end
        GithubScriptStep-->>CommentWorkflow: finish step
    end

    CommentWorkflow-->>GitHubActions: job completed
Loading

更新された GitHub Actions スクリプト内でのコメント有無の判断ロジックのフローダイアグラム

flowchart TD
    A[Start github-script step] --> B[Read prNumber from pr_number/pr_number.txt]
    B --> C[Strip non digit characters from prNumber]
    C --> D[Read comment text from comment/comment.txt]
    D --> E[Call GitHub API issues.listComments with prNumber]
    E --> F[Find existing bot comment containing WORKFLOW_NAME]
    F --> G{oldComment exists
    OR CONCLUSION equals failure}
    G -->|No| H[Do not comment]
    H --> Z[End]
    G -->|Yes| I{oldComment exists?}
    I -->|Yes| J[Update existing comment with new comment text]
    I -->|No| K[Create new PR comment with comment text]
    J --> Z
    K --> Z
Loading

ファイル単位の変更点

変更点 詳細 ファイル
シェルで組み立てた環境変数や process.env をコメント本文に使わないようにするため、PR 番号とコメント取得処理を github-script ステップ内に移動。
  • PR_NUMBER と COMMENT を GITHUB_ENV にエクスポートしていたシェルベースの「Setup Environment」ステップを削除。
  • github-script ステップ内で Node の fs を使って pr_number/pr_number.txt と comment/comment.txt を読み込み、PR 番号から数字以外の文字を除去してサニタイズ。
  • process.env.PR_NUMBER の使用箇所を、ローカルで計算した prNumber 変数に置き換え。
  • process.env.COMMENT の使用箇所を、ローカルで読み込んだ comment 文字列に置き換え。
  • listComments の find コールバック内の変数名をわずかに変更し、comment のシャドーイングによる混乱を避ける。
.github/workflows/comment.yml
Bun lockfile の追跡メタデータを更新。
  • .mise/prepare-state.toml 内の bun.lock 用の expected hash を、新しい lockfile の内容に一致するように変更。
  • 再生成された bun.lock をコミットし、必要に応じて .gitignore の調整も含めて正しく追跡/無視されることを確認。
.mise/prepare-state.toml
bun.lock
.gitignore

Tips とコマンド

Sourcery とのやり取り

  • 新しいレビューを開始する: プルリクエストに @sourcery-ai review とコメントします。
  • ディスカッションを続ける: Sourcery のレビューコメントに直接返信します。
  • レビューコメントから GitHub Issue を作成する: 対象のレビューコメントに返信して、Issue の作成を Sourcery に依頼します。レビューコメントに @sourcery-ai issue と返信して Issue を作成することもできます。
  • プルリクエストのタイトルを生成する: プルリクエストのタイトルのどこかに @sourcery-ai と書くと、いつでもタイトルを生成できます。プルリクエストに @sourcery-ai title とコメントして、タイトルをいつでも(再)生成することもできます。
  • プルリクエストのサマリを生成する: プルリクエスト本文の任意の場所に @sourcery-ai summary と書くと、ちょうどその位置に PR サマリをいつでも生成できます。プルリクエストに @sourcery-ai summary とコメントして、サマリをいつでも(再)生成することもできます。
  • レビュー担当者向けガイドを生成する: プルリクエストに @sourcery-ai guide とコメントして、レビュー担当者向けガイドをいつでも(再)生成できます。
  • すべての Sourcery コメントを解決済みにする: プルリクエストに @sourcery-ai resolve とコメントして、Sourcery のコメントをすべて解決済みにします。すでにすべてのコメントに対応済みで、これ以上表示したくない場合に便利です。
  • すべての Sourcery レビューを却下する: プルリクエストに @sourcery-ai dismiss とコメントして、既存の Sourcery レビューをすべて却下します。新しいレビューで仕切り直したいときに特に有用です。その際は新しいレビューを開始するために @sourcery-ai review とコメントするのを忘れないでください。

体験をカスタマイズする

ダッシュボード にアクセスすると、次のことができます:

  • Sourcery が生成するプルリクエストサマリやレビュー担当者向けガイドなどのレビュー機能を有効/無効化。
  • レビュー言語の変更。
  • カスタムレビュー指示の追加・削除・編集。
  • その他のレビュー設定の調整。

ヘルプを受ける

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the GitHub Actions comment workflow to read PR number and comment text directly from files inside the github-script step instead of environment variables, eliminating unsafe env interpolation, and updates Bun lock/prepare-state metadata accordingly.

Sequence diagram for updated PR comment GitHub Actions workflow

sequenceDiagram
    participant GitHubActions
    participant CommentWorkflow
    participant GithubScriptStep
    participant FileSystem
    participant GitHubAPI

    GitHubActions->>CommentWorkflow: Trigger on workflow_run
    CommentWorkflow->>GithubScriptStep: Run actions/github-script

    GithubScriptStep->>FileSystem: readFile pr_number/pr_number.txt
    FileSystem-->>GithubScriptStep: prNumber (digits only)
    GithubScriptStep->>FileSystem: readFile comment/comment.txt
    FileSystem-->>GithubScriptStep: comment body text

    GithubScriptStep->>GitHubAPI: issues.listComments(owner, repo, prNumber)
    GitHubAPI-->>GithubScriptStep: existing PR comments

    GithubScriptStep->>GithubScriptStep: find existing bot comment matching WORKFLOW_NAME
    GithubScriptStep->>GithubScriptStep: determine shouldComment using CONCLUSION and oldComment
    alt shouldComment is false
        GithubScriptStep-->>CommentWorkflow: exit without commenting
    else shouldComment is true
        alt oldComment exists
            GithubScriptStep->>GitHubAPI: issues.updateComment(commentId, new body)
            GitHubAPI-->>GithubScriptStep: updated comment
        else no oldComment
            GithubScriptStep->>GitHubAPI: issues.createComment(prNumber, comment)
            GitHubAPI-->>GithubScriptStep: created comment
        end
        GithubScriptStep-->>CommentWorkflow: finish step
    end

    CommentWorkflow-->>GitHubActions: job completed
Loading

Flow diagram for comment decision logic in updated GitHub Actions script

flowchart TD
    A[Start github-script step] --> B[Read prNumber from pr_number/pr_number.txt]
    B --> C[Strip non digit characters from prNumber]
    C --> D[Read comment text from comment/comment.txt]
    D --> E[Call GitHub API issues.listComments with prNumber]
    E --> F[Find existing bot comment containing WORKFLOW_NAME]
    F --> G{oldComment exists
    OR CONCLUSION equals failure}
    G -->|No| H[Do not comment]
    H --> Z[End]
    G -->|Yes| I{oldComment exists?}
    I -->|Yes| J[Update existing comment with new comment text]
    I -->|No| K[Create new PR comment with comment text]
    J --> Z
    K --> Z
Loading

File-Level Changes

Change Details Files
Move PR number and comment retrieval into the github-script step to avoid using shell-built environment variables and process.env for comment content.
  • Remove the shell-based 'Setup Environment' step that exported PR_NUMBER and COMMENT into GITHUB_ENV.
  • Within the github-script step, add Node fs reads of pr_number/pr_number.txt and comment/comment.txt, sanitizing the PR number by stripping non-digits.
  • Replace usages of process.env.PR_NUMBER with the locally computed prNumber variable.
  • Replace usage of process.env.COMMENT with the locally loaded comment string.
  • Slightly adjust the listComments find callback variable name to avoid confusing shadowing of 'comment'.
.github/workflows/comment.yml
Update Bun lockfile tracking metadata.
  • Change the expected hash for bun.lock in .mise/prepare-state.toml to match the new lockfile contents.
  • Commit regenerated bun.lock and ensure it is correctly tracked/ignored alongside .gitignore adjustments if any.
.mise/prepare-state.toml
bun.lock
.gitignore

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - いくつか高レベルなフィードバックを残しました。

  • pr_number/pr_number.txt をパースする際、ファイルが存在しない場合や、結果として得られた prNumber が空の場合を明示的にハンドリングすることを検討してください。そうすることで、暗黙の失敗や無効な issue 番号にコメントを作成してしまうことを防げます。
  • ファイルから読み込んだ後の prNumbercomment の値に対して trim() を実行しておくと、想定外の末尾の空白や改行が GitHub API 呼び出しに影響するのを防げるので、より安全かもしれません。
AI エージェント向けプロンプト
Please address the comments from this code review:

## Overall Comments
- When parsing `pr_number/pr_number.txt`, consider explicitly handling the case where the file is missing or the resulting `prNumber` is empty to avoid silently failing or creating comments on an invalid issue number.
- It may be safer to `trim()` the `prNumber` and `comment` values after reading from the files to guard against unexpected trailing whitespace or newline issues affecting the GitHub API calls.

Sourcery はオープンソースには無料です - レビューを気に入っていただけたら、ぜひシェアをお願いします ✨
もっと役に立てるように手助けしてください! 各コメントに 👍 または 👎 を付けていただけると、そのフィードバックをもとにレビューを改善していきます。
Original comment in English

Hey - I've left some high level feedback:

  • When parsing pr_number/pr_number.txt, consider explicitly handling the case where the file is missing or the resulting prNumber is empty to avoid silently failing or creating comments on an invalid issue number.
  • It may be safer to trim() the prNumber and comment values after reading from the files to guard against unexpected trailing whitespace or newline issues affecting the GitHub API calls.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When parsing `pr_number/pr_number.txt`, consider explicitly handling the case where the file is missing or the resulting `prNumber` is empty to avoid silently failing or creating comments on an invalid issue number.
- It may be safer to `trim()` the `prNumber` and `comment` values after reading from the files to guard against unexpected trailing whitespace or newline issues affecting the GitHub API calls.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Overview

Image reference marukome0743/dcrs:canary marukome0743/dcrs:pr-1466
- digest aad3deef1838 378dca6594e2
- tag canary pr-1466
- provenance 7896cea
- vulnerabilities critical: 0 high: 1 medium: 0 low: 9 unspecified: 5 critical: 0 high: 0 medium: 0 low: 0
- platform linux/amd64 linux/amd64
- size 80 MB 92 MB (+12 MB)
- packages 177 182 (+5)
Base Image distroless/static:nonroot distroless/static:nonroot
- vulnerabilities critical: 0 high: 0 medium: 0 low: 0 critical: 0 high: 0 medium: 0 low: 0
Labels (3 changes)
  • ± 3 changed
  • 5 unchanged
-org.opencontainers.image.created=2026-04-09T00:15:19.172Z
+org.opencontainers.image.created=2026-04-09T12:35:27.791Z
 org.opencontainers.image.description=Disability Certificate Register System📇
 org.opencontainers.image.licenses=Apache-2.0
-org.opencontainers.image.revision=40f746168ba8600ef4ed935427272cb5d6098239
+org.opencontainers.image.revision=7896cea2be21ae15351995e28c09bb5fab9ad0a9
 org.opencontainers.image.source=https://github.com/OpenUp-LabTakizawa/dcrs
 org.opencontainers.image.title=dcrs
 org.opencontainers.image.url=https://github.com/OpenUp-LabTakizawa/dcrs
-org.opencontainers.image.version=canary
+org.opencontainers.image.version=pr-1466
Packages and Vulnerabilities (5 package changes and 1 vulnerability changes)
  • ➕ 5 packages added
  • 172 packages unchanged
  • ✔️ 1 vulnerabilities removed
Changes for packages of type deb (5 changes)
Package Version
marukome0743/dcrs:canary
Version
marukome0743/dcrs:pr-1466
gcc-14 14.2.0-19
glibc 2.41-12+deb13u2
libzstd 1.5.7+dfsg-1
openssl 3.5.5-1~deb13u1
zlib 1:1.3.dfsg+really1.3.1-1

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dcrs Ready Ready Preview, Comment Apr 9, 2026 0:41am

@Marukome0743 Marukome0743 merged commit 3a6486a into OpenUp-LabTakizawa:main Apr 9, 2026
22 checks passed
@Marukome0743 Marukome0743 deleted the pr1466 branch April 9, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

♻️ci Changes to CI configuration files and scripts dependencies Pull requests that update a dependency file 🪸git Modify .gitattributes and .gitignore 🧰infrastructure Improvements of facility such as linter etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants