Skip to content

Add runtime check to disallow pull_request_target event on public repositories#22378

Merged
pelikhan merged 3 commits intomainfrom
copilot/add-runtime-check-pull-request-target
Mar 23, 2026
Merged

Add runtime check to disallow pull_request_target event on public repositories#22378
pelikhan merged 3 commits intomainfrom
copilot/add-runtime-check-pull-request-target

Conversation

Copy link
Contributor

Copilot AI commented Mar 23, 2026

pull_request_target runs in the base repo context with full secret access even when triggered from a fork, making it a "pwn request" vector on public repos. This adds a runtime enforcement check alongside the existing strict-mode and lockdown checks.

Changes

  • validate_lockdown_requirements.cjs — Added check after strict-mode enforcement: reads GITHUB_EVENT_NAME + GITHUB_REPOSITORY_VISIBILITY; fails the workflow with a descriptive error if pull_request_target fires on a public repo. Sets lockdown_check_failed=true output for consistency with other guards.

  • validate_lockdown_requirements.test.cjs — 7 new test cases covering: fail on public+pull_request_target, pass on public+pull_request, pass on private/internal regardless of strict mode, pass when visibility unknown, correct ordering when strict-mode check also fails.

The check only blocks public repos — private and internal repos are unaffected.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI changed the title [WIP] Add runtime check for pull_request_target in public repositories Add runtime check to disallow pull_request_target event on public repositories Mar 23, 2026
Copilot AI requested a review from pelikhan March 23, 2026 04:46
@pelikhan pelikhan marked this pull request as ready for review March 23, 2026 05:00
Copilot AI review requested due to automatic review settings March 23, 2026 05:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a runtime guard to block GitHub Actions workflows from running on pull_request_target in public repositories, reducing exposure to “pwn request” style attacks.

Changes:

  • Added a runtime check in validate_lockdown_requirements.cjs to fail the workflow when GITHUB_EVENT_NAME=pull_request_target and GITHUB_REPOSITORY_VISIBILITY=public, emitting lockdown_check_failed=true.
  • Added Vitest coverage for pull_request_target enforcement scenarios and ordering relative to strict-mode failures.
  • Updated test setup to reset GITHUB_EVENT_NAME between tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
actions/setup/js/validate_lockdown_requirements.cjs Introduces the public-repo pull_request_target runtime enforcement and failure message/output behavior.
actions/setup/js/validate_lockdown_requirements.test.cjs Adds test cases validating the new enforcement behavior and its interaction with strict-mode checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"\\n" +
"The pull_request_target event is not allowed on public repositories because it runs\\n" +
"workflows with access to repository secrets even when triggered from a fork, which\\n" +
'creates a significant security risk (known as a \\"pwn request\\").\\n' +
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The error message string is escaping quotes incorrectly: \"pwn request\" in a single-quoted JS string will render with literal backslashes (e.g., \"pwn request\") in the output. Use unescaped double quotes ("pwn request" in a double-quoted string) or just "pwn request" without extra backslashes (e.g., known as a "pwn request" or known as a "pwn request" via a template literal) so the message prints cleanly.

Suggested change
'creates a significant security risk (known as a \\"pwn request\\").\\n' +
'creates a significant security risk (known as a "pwn request").\\n' +

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Contributor

@copilot Apply reviews

Copy link
Contributor Author

Copilot AI commented Mar 23, 2026

@copilot Apply reviews

Fixed in 38ee570 — changed 'creates a significant security risk (known as a \\"pwn request\\").\\n' to 'creates a significant security risk (known as a "pwn request").\\n' so the quotes render cleanly without literal backslashes.

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.

3 participants