Skip to content
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
81db9f3
docs: untrusted code risks in actions
wrslatz Apr 29, 2025
e4df5a1
docs: expand pull_request_target warning links
wrslatz Apr 29, 2025
bccd376
docs: warning for workflow_run security risks
wrslatz Apr 29, 2025
e6a50fb
Update content/actions/how-tos/security-for-github-actions/security-g…
Sharra-writes Jul 10, 2025
834a877
Update content/actions/how-tos/security-for-github-actions/security-g…
Sharra-writes Jul 10, 2025
809c2c5
Update content/actions/how-tos/security-for-github-actions/security-g…
Sharra-writes Jul 10, 2025
d03bd88
Update data/reusables/actions/pull-request-target-permissions-warning.md
Sharra-writes Jul 10, 2025
b1ff7f6
Update data/reusables/actions/workflow-run-permissions-warning.md
Sharra-writes Jul 10, 2025
1871bfa
docs: sync hardening info to enterprise-onboarding
wrslatz Jul 10, 2025
153ca42
docs: fix grammar and improve content in reusables
wrslatz Jul 14, 2025
f710cb9
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Aug 7, 2025
ae2c0e4
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Aug 11, 2025
ca12535
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Aug 12, 2025
36b6336
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Aug 13, 2025
9bde44a
Merge branch 'main' into gha-hardening-pull-request-target
Sharra-writes Aug 13, 2025
f38780a
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Aug 26, 2025
205713f
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Sep 3, 2025
8f7d1fa
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Sep 5, 2025
2b28b60
Merge branch 'main' into gha-hardening-pull-request-target
wrslatz Sep 9, 2025
3b24c7d
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 12, 2025
454725d
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 12, 2025
135ce49
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 12, 2025
1d8099b
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 12, 2025
8989d45
docs: change product reference
wrslatz Sep 12, 2025
2b8e32b
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 12, 2025
f3d1e1a
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 12, 2025
d77656f
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 12, 2025
07e97d8
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 12, 2025
5301aa9
Update data/reusables/actions/pull-request-target-permissions-warning.md
Sharra-writes Sep 12, 2025
3253a3b
Update data/reusables/actions/workflow-run-permissions-warning.md
Sharra-writes Sep 12, 2025
90927fe
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 12, 2025
833242a
Update data/reusables/actions/pull-request-target-permissions-warning.md
Sharra-writes Sep 12, 2025
ba5b0c4
Update data/reusables/actions/workflow-run-permissions-warning.md
Sharra-writes Sep 12, 2025
e6153eb
Merge branch 'main' into gha-hardening-pull-request-target
Sharra-writes Sep 12, 2025
4167523
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 15, 2025
50618ff
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 15, 2025
19e739b
Update content/enterprise-onboarding/github-actions-for-your-enterpri…
Sharra-writes Sep 15, 2025
a13ba38
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 15, 2025
1cc35aa
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 15, 2025
b317ec0
Merge branch 'main' into gha-hardening-pull-request-target
Sharra-writes Sep 16, 2025
1fff644
Merge branch 'main' into gha-hardening-pull-request-target
Sharra-writes Sep 16, 2025
5d3f38c
Apply suggestions from code review
Sharra-writes Sep 17, 2025
efa1115
Apply suggestions from code review
Sharra-writes Sep 17, 2025
4794b55
Apply suggestions from code review
Sharra-writes Sep 17, 2025
824f535
Update content/actions/reference/security/secure-use.md
Sharra-writes Sep 17, 2025
50f9ae8
Apply suggestions from code review
Sharra-writes Sep 18, 2025
432e516
Apply suggestions from code review
Sharra-writes Sep 18, 2025
3fabf02
Merge branch 'main' into gha-hardening-pull-request-target
Sharra-writes Sep 18, 2025
0d1f3c6
Apply suggestions from code review
Sharra-writes Sep 18, 2025
da2130b
Apply suggestions from code review
Sharra-writes Sep 19, 2025
16f560b
Merge branch 'main' into gha-hardening-pull-request-target
Sharra-writes Sep 19, 2025
8b3853e
Update content/actions/reference/security/secure-use.md
subatoi Sep 19, 2025
270e3d3
Update content/actions/reference/security/secure-use.md
subatoi Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion content/actions/reference/security/secure-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,30 @@ For more information, see [AUTOTITLE](/code-security/code-scanning/introduction-

To help mitigate the risk of an exposed token, consider restricting the assigned permissions. For more information, see [AUTOTITLE](/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token).

### Using third-party actions
{% ifversion custom-org-roles %}

## Mitigating the risks of untrusted code checkout

Similar to script injection attacks, untrusted pull request content that automatically triggers actions processing can also pose a security risk. The `pull_request_target` and `workflow_run` workflow triggers, when used with the checkout of an untrusted pull request, expose the repository to security compromises. These workflows are privileged, which means they share the same cache of the main branch with other privileged workflow triggers, and may have repository write access and access to referenced secrets. These vulnerabilities can be exploited to take over a repository.

For more information on these triggers, how to use them, and the associated risks, see [AUTOTITLE](/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target) and [AUTOTITLE](/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run).

For additional examples and guidance on the risks of untrusted code checkout, see [Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) from {% data variables.product.prodname_security %} and the [Dangerous-Workflow](https://github.com/ossf/scorecard/blob/main/docs/checks.md#dangerous-workflow) documentation from OpenSSF Scorecard.

### Good practices


* Avoid using the `pull_request_target` workflow trigger if it's not necessary. For privilege separation between workflows, `workflow_run` is a better trigger. Only use these workflow triggers when the workflow actually needs the privileged context.

* Avoid using the `pull_request_target` and `workflow_run` workflow triggers with untrusted pull requests or code content. Workflows that use these triggers must not explicitly check out untrusted code, including from pull request forks or from repositories that are not under your control. Workflows triggered on `workflow_run` should treat artifacts uploaded from other workflows with caution.

* {% data variables.product.prodname_codeql %} can scan and detect potentially vulnerable {% data variables.product.prodname_actions %} workflows. You can configure default setup for the repository, and ensure that {% data variables.product.prodname_actions %} scanning is enabled. For more information, see [AUTOTITLE](/code-security/code-scanning/enabling-code-scanning/configuring-default-setup-for-code-scanning).

* OpenSSF Scorecards can help you identify potentially vulnerable workflows, along with other security risks when using {% data variables.product.prodname_actions %}. See [Using OpenSSF Scorecards to secure workflow dependencies](#use-openssf-scorecards-to-detect-potentially-vulnerable-workflows) later in this article.

{% endif %}

## Using third-party actions

The individual jobs in a workflow can interact with (and compromise) other jobs. For example, a job querying the environment variables used by a later job, writing files to a shared directory that a later job processes, or even more directly by interacting with the Docker socket and inspecting other running containers and executing commands in them.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,8 @@ For more information, see the {% data variables.product.prodname_cli %} informat

This event occurs when a workflow run is requested or completed. It allows you to execute a workflow based on execution or completion of another workflow. The workflow started by the `workflow_run` event is able to access secrets and write tokens, even if the previous workflow was not. This is useful in cases where the previous workflow is intentionally not privileged, but you need to take a privileged action in a later workflow.

{% data reusables.actions.workflow-run-permissions-warning %}

In this example, a workflow is configured to run after the separate "Run Tests" workflow completes.

```yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ In this example, the attempted script injection is unsuccessful, which is reflec
PR title did not start with 'octocat'
```

With this approach, the value of the {% raw %}`${{ github.event.issue.title }}`{% endraw %} expression is stored in memory and used as a variable, and doesn't interact with the script generation process. In addition, consider using double quote shell variables to avoid [word splitting](https://github.com/koalaman/shellcheck/wiki/SC2086), but this is [one of many](https://mywiki.wooledge.org/BashPitfalls) general recommendations for writing shell scripts, and is not specific to {% data variables.product.prodname_actions %}.
With this approach, the value of the {% raw %}`${{ github.event.pull_request.title }}`{% endraw %} expression is stored in memory and used as a variable, and doesn't interact with the script generation process. In addition, consider using double quote shell variables to avoid [word splitting](https://github.com/koalaman/shellcheck/wiki/SC2086), but this is [one of many](https://mywiki.wooledge.org/BashPitfalls) general recommendations for writing shell scripts, and is not specific to {% data variables.product.prodname_actions %}.

### Using workflow templates for {% data variables.product.prodname_code_scanning %}

Expand All @@ -152,6 +152,10 @@ For more information, see [AUTOTITLE](/code-security/code-scanning/introduction-

To help mitigate the risk of an exposed token, consider restricting the assigned permissions. For more information, see [AUTOTITLE](/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token).

## Understanding the risks of untrusted code checkout

Untrusted pull request content that automatically triggers actions processing can pose a security risk. For more information, see [AUTOTITLE](/enterprise-cloud@latest/actions/reference/security/secure-use#mitigating-the-risks-of-untrusted-code-checkout) in the {% data variables.product.prodname_ghe_cloud %} documentation.

## Managing permissions for {% data variables.product.prodname_actions %} settings in your organization

You can practice the principle of least privilege for your organization's CI/CD pipeline with {% data variables.product.prodname_actions %} by administering custom organization roles. A custom organization role is a way to grant an individual or team in your organization the ability to control certain subsets of settings without granting full administrative control of the organization and its repositories.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
> [!WARNING]
> For workflows that are triggered by the `pull_request_target` event, the `GITHUB_TOKEN` is granted read/write repository permission unless the `permissions` key is specified and the workflow can access secrets, even when it is triggered from a fork. Although the workflow runs in the context of the base of the pull request, you should make sure that you do not check out, build, or run untrusted code from the pull request with this event. Additionally, any caches share the same scope as the base branch. To help prevent cache poisoning, you should not save the cache if there is a possibility that the cache contents were altered. For more information, see [Keeping your GitHub Actions and workflows secure: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests) on the GitHub Security Lab website.
> Running untrusted code on the `pull_request_target` trigger may lead to security vulnerabilities. These vulnerabilities include cache poisoning and granting unintended access to write privileges or secrets. For more information, see [AUTOTITLE](/enterprise-cloud@latest/actions/reference/security/secure-use#mitigating-the-risks-of-untrusted-code-checkout) in the {% data variables.product.prodname_ghe_cloud %} documentation, and [Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests) on the {% data variables.product.prodname_security %} website.
2 changes: 2 additions & 0 deletions data/reusables/actions/workflow-run-permissions-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> [!WARNING]
> Running untrusted code on the `workflow_run` trigger may lead to security vulnerabilities. These vulnerabilities include cache poisoning and granting unintended access to write privileges or secrets. For more information, see [AUTOTITLE](/enterprise-cloud@latest/actions/reference/security/secure-use#mitigating-the-risks-of-untrusted-code-checkout) in the {% data variables.product.prodname_ghe_cloud %} documentation, and [Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests) on the {% data variables.product.prodname_security %} website.
Loading