Skip to content

ci: fork-gate maven-sonar-build's ~/.m2 cache save; JSON-encode eslint_has_findings in ui-checkstyle - #35420

Merged
pmbrull merged 1 commit into
mainfrom
pmbrull/ci-pull-request-target-hardening
Oct 14, 2026
Merged

pmbrull merged 1 commit into
mainfrom
pmbrull/ci-pull-request-target-hardening

Conversation

@pmbrull

@pmbrull pmbrull commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

No linked issue — two hardening fixes from an audit of the workflows that run on pull_request_target. Follow-up to #32436 and #32468; #32468 listed maven-sonar-build.yml as still unguarded.

Correction: GitHub now gives pull_request_target runs read-only access to the cache by default (current runs log Cache mode: read), so the unguarded save in item 1 could not actually write into main's scope. Item 1 is hardening, not a fix for a live write path. Item 2 stands.

1. maven-sonar-build.yml — unguarded ~/.m2 cache save under pull_request_target. The workflow triggers on pull_request_target and checks out the PR head (allow-unsafe-pr-checkout: true), so it runs in the base branch's cache scope with the PR's build on disk. Its combined actions/cache@v6 then saved ~/.m2 after the job with no fork guard. The key hashes **/pom.xml only, and the ${{ runner.os }}-maven- restore prefix is shared by the merge-queue Playwright build, release-branch-validate.yml, integration-tests-postgres-elasticsearch-redis.yml and the nightlies, so whatever a fork run left in ~/.m2 could be restored by trusted runs.

2. ui-checkstyle.yml — a PR-controlled job output was interpolated raw into github-script. The ui-checkstyle job (pull-requests: write) builds its PR comment in actions/github-script and read eslint_has_findings as '${{ needs.checkstyle.outputs.eslint_has_findings }}'. That output is written to $GITHUB_OUTPUT by scripts/eslint-pr-report.js from the PR checkout, so a value containing a quote closed the string literal and the rest ran as script in the privileged job. It is now wrapped in toJSON, like eslint_summary and eslint_details next to it. The other expressions in that script were already safe: the *_changed_files outputs go through toJSON, and the *_result outputs, needs.checkstyle.result and the comment id come from the runner or the API.

Both paths already required the safe to test label.

Type of change:

  • Improvement

High-level design:

N/A — small change, two workflow files.

maven-sonar-build.yml now uses an ungated actions/cache/restore@v6 and a fork-gated actions/cache/save@v6 after Build with Maven:

      - name: Save Maven dependencies
        if: >-
          steps.maven-cache.outputs.cache-hit != 'true' &&
          !(github.event_name == 'pull_request_target' &&
            github.event.pull_request.head.repo.full_name != github.repository)
        continue-on-error: true
        uses: actions/cache/save@v6
        with:
          path: ~/.m2
          key: ${{ steps.maven-cache.outputs.cache-primary-key }}
  • The restore stays ungated, so fork PRs still start from a warm ~/.m2. Only the write is gated, the same shape as playwright-knowledge-graph-postgresql-e2e.yml and playwright-e2e-reusable.yml.
  • cache-hit != 'true' keeps the combined action's skip on an exact hit, and the save step inherits the implicit success(), as the combined action's post-if: success() did.
  • The save reuses the restore's cache-primary-key instead of evaluating hashFiles('**/pom.xml') again after the build, so restore and save cannot end up on different keys.

ui-checkstyle.yml:

-            const eslintFindings = '${{ needs.checkstyle.outputs.eslint_has_findings }}' === 'true';
+            const eslintFindings = ${{ toJSON(needs.checkstyle.outputs.eslint_has_findings) }} === 'true';

Rollout: both workflows run on pull_request_target, which always uses main's copy of the workflow file, so this PR's own checks still run the old versions and the change takes effect on merge. Same-repo PRs and workflow_dispatch runs save the Maven cache as before; fork PRs restore it but no longer write.

Tests:

Use cases covered

  • Fork PR under pull_request_target (maven-sonar-build): restores ~/.m2, writes nothing into the base-branch cache scope.
  • Same-repo PR / workflow_dispatch (maven-sonar-build): restore and save as before; an exact hit skips the save.
  • ui-checkstyle comment: has_findings of true, false or empty behaves exactly as before; a value containing ' is read as a plain string.

Unit tests

Not applicable — CI configuration only.

Backend integration tests

Not applicable — no Java changes.

Ingestion integration tests

Not applicable — no ingestion changes.

Playwright (UI) tests

Not applicable — no UI changes.

Manual testing performed

  1. yaml.safe_load on both changed files — both parse.
  2. Asserted on maven-sonar-build.yml: no combined actions/cache@vN is left; the restore has no if:; the save carries the fork guard and the cache-hit check, comes after Build with Maven, and uses the restore's path and primary key.
  3. actionlint on both files: maven-sonar-build.yml is clean; ui-checkstyle.yml reports the same 25 shellcheck info/style notes on main and on this branch, none on the changed line.
  4. Rendered the Post or update summary comment script from main and from this branch the way the expression engine does (toJSON gives a JSON string literal, a bare expression gives raw text) and ran each in node against a mocked GitHub client:
eslint_has_findings main this branch
true comment posted comment posted
false / empty no comment no comment
value that closes the quote and appends a statement appended statement runs read as a string, no comment

UI screen recording:

Not applicable — CI configuration only.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation> — no linked issue; CI hardening, labelled skip-pr-checks.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above — see above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable, no schema changes.
  • For a UI feature or feature task: not applicable, no UI changes.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above — not applicable, CI configuration only; the manual checks are listed above.
  • Decision check: no new decision — this applies the existing fork-guard pattern.

🤖 Generated with Claude Code

…lint_has_findings

maven-sonar-build runs on pull_request_target and builds the PR head, but
its combined actions/cache@v6 saved ~/.m2 post-job with no fork guard, so a
fork run wrote into main's cache scope. Split it into an ungated restore and
a fork-gated save keyed on the restore's cache-primary-key, matching the
other Maven caches fixed in #32436 and #32468.

ui-checkstyle's privileged comment job interpolated eslint_has_findings raw
inside a quoted JS string. That output is written by the PR's own
scripts/eslint-pr-report.js, so wrap it in toJSON like the two outputs next
to it.
@pmbrull pmbrull added the skip-pr-checks Bypass PR metadata validation check label Oct 14, 2026
@pmbrull
pmbrull requested review from a team, akash-jain-10, harshach and tutte as code owners October 14, 2026 08:10
@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 14, 2026
@gitar-bot

gitar-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Fork-gating Maven cache saves and JSON-encoding PR-controlled output alter privileged workflow protections; regressions could re-enable cache poisoning or script injection.

Two CI hardening fixes: maven-sonar-build.yml now restores ~/.m2 on all runs but only saves it for non-fork PRs, and ui-checkstyle.yml wraps eslint_has_findings in toJSON to prevent script injection in the privileged github-script step. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@pmbrull
pmbrull added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 6162d5d Oct 14, 2026
116 checks passed
@pmbrull
pmbrull deleted the pmbrull/ci-pull-request-target-hardening branch October 14, 2026 19:33
pmbrull added a commit that referenced this pull request Oct 20, 2026
Conflicts:
- .github/workflows/maven-sonar-build.yml: kept this branch's save condition
  (cache-hit only). Main carries #35420's fork guard for pull_request_target,
  which can no longer fire now that the workflow triggers on pull_request.

Follow-up from main: REVIEW.md asked reviewers to check that a missing
`safe to test` label did not skip a job; that label is retired here, so the
item now names the fork and Dependabot skips instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants