返回提示词目录第 1355 页

代码仓库自动化工作流安全审计

追踪工作流触发器、权限与不可信输入,识别密钥泄露和越权部署链路,形成证据化审计报告。

完整提示词

I want a complete forensic audit of all GitHub Actions workflows with a focus on supply chain, secrets, permissions, untrusted pull requests, deployment authority, and expression/script injection.

Main objective:

> Determine whether a contributor, compromised dependency/action, malicious PR, tag, branch, or workflow input can lead to secrets theft, repository write access, package publishing, release tampering, or unauthorized production deployments.

## 1. INVENTORY

All:

```text
.github/workflows/*.yml
.github/actions/*
```

plus reusable workflows.

For each workflow:

```text
Name:
Triggers:
Permissions:
Secrets:
Environment:
Runner:
External actions:
Deployment:
Artifacts:
```

## 2. TRIGGERS

Review:

- push

- pull_request

- pull_request_target

- workflow_dispatch

- workflow_run

- schedule

- release

- issue_comment

- repository_dispatch

## 3. `pull_request`

Code originating from forks is untrusted.

Verify GitHub secret exposure semantics against the actual event trigger.

## 4. `pull_request_target`

High-value attack surface.

The workflow executes in the context of the base repository and can access elevated privileges.

## 5. DANGEROUS COMBINATION

```text
pull_request_target
+
checkout PR head
+
execute code
+
secrets/write token
```

P0/P1 candidate.

## 6. CHECKOUT REF

Identify precisely what commit SHA is checked out:

- base SHA

- merge commit

- head SHA

- arbitrary user input

## 7. `workflow_run`

A privileged follow-up workflow can process artifacts generated by an untrusted workflow.

## 8. ARTIFACT TRUST

An artifact is not inherently trusted merely because it originates from another workflow.

## 9. ARTIFACT POISONING

Untrusted build artifact -> privileged workflow executes the included file or script.

## 10. `workflow_dispatch`

Audit inputs.

## 11. USER-CONTROLLED EXPRESSION IN SHELL

High-signal:

```yaml
run: echo "${{ github.event.issue.title }}"
```

If content can contain shell syntax and string interpolation injects directly into the generated script.

## 12. SAFE ENV INDIRECTION

Prefer passing untrusted expressions into environment variables, then applying language-appropriate shell quoting.

## 13. PR TITLE/BODY/BRANCH

Attacker-controlled inputs.

## 14. ISSUE COMMENT

Attacker-controlled subject to repository permission settings.

## 15. COMMIT MESSAGE

Potential attacker input.

## 16. MATRIX

Matrix values derived from dynamic JSON can influence commands and runner selections.

## 17. PERMISSIONS

Review top-level and job-level:

```yaml
permissions:
```

## 18. DEFAULT TOKEN

Do not presume token permissions.

Determine the actual declared or default repository context.

## 19. `contents: write`

Analyze why it is required.

## 20. `actions: write`

Can modify or trigger workflow states.

## 21. `packages: write`

Direct supply-chain impact.

## 22. `id-token: write`

OIDC cloud authentication.

Extremely high-value permission.

## 23. `pull-requests: write`

Lower direct impact, but useful for attacker persistence and social engineering vectors.

## 24. MINIMAL PER JOB

Deploy permissions must not be granted to build or test jobs.

## 25. SECRETS

Inventory names only, never secret values.

## 26. SECRET SCOPE

Which job and step receives:

- deploy token

- registry token

- signing key

- cloud credential

## 27. ENVIRONMENT SECRETS

Production environment protection rules.

## 28. APPROVAL

If the workflow deploys to production:

verify environment reviewers and protection rules if accessible.

## 29. OIDC

If the cloud provider supports OIDC:

analyze subject, audience, repository, and branch trust bindings.

## 30. STATIC CLOUD SECRET

Not automatically a flaw, but long-lived credentials carry a larger blast radius.

## 31. OIDC TRUST POLICY

Critical:

> Which repository, workflow, branch/tag, or environment can assume the cloud role?

## 32. WILDCARD SUBJECT

Can permit untrusted branches or PRs to assume production roles.

## 33. THIRD-PARTY ACTION

Every:

```text
uses: owner/action@ref
```

is an executable third-party dependency.

## 34. SHA PINNING

Strong immutability assurance.

## 35. MAJOR TAG

`@v4` can be mutable.

P4/P2 depending on secrets and token permissions.

## 36. `@main`

High-risk for privileged workflows.

## 37. DOCKER ACTION

Can execute arbitrary container code.

## 38. JS ACTION

Likewise.

## 39. COMPOSITE ACTION

Can invoke shell commands and additional actions.

## 40. REUSABLE WORKFLOW

External repository and ref trust boundaries.

## 41. ACTION OWNER

Compromise of the upstream action owner can pivot directly into your CI environment.

## 42. `curl | bash`

High-value attack surface.

## 43. REMOTE BINARY DOWNLOAD

Must enforce version pinning plus checksum or cryptographic signature verification.

## 44. SETUP ACTIONS

Pin compiler and toolchain versions.

## 45. DEPENDENCY INSTALL

Package lifecycle scripts execute inside the CI runner.

## 46. SECRETS BEFORE INSTALL

If secrets are already present in the environment prior to untrusted dependency installation:

risk escalates sharply.

## 47. `npm install` PR

A malicious contributor can alter package lifecycle scripts.

## 48. BUILD SCRIPT

Repository code is executable code.

## 49. SELF-HOSTED RUNNER

Critical trust boundary.

## 50. PUBLIC REPO + SELF-HOSTED

Executing untrusted pull requests is extremely high-risk.

## 51. RUNNER PERSISTENCE

A self-hosted runner can retain:

- files

- credentials

- Docker daemon state

- orphaned processes

from prior jobs.

## 52. EPHEMERAL RUNNER

Mitigates persistence across executions.

## 53. RUNNER LABEL

Can an untrusted workflow target a privileged runner?

## 54. NETWORK ACCESS

A runner may possess access to internal private infrastructure.

## 55. DOCKER SOCKET

A CI runner with access to the Docker socket holds high host privilege.

## 56. GITHUB-HOSTED

The ephemeral model mitigates host persistence, but secrets and token permissions remain crucial.

## 57. CACHE

A cache created by an untrusted branch can subsequently poison a privileged job.

## 58. CACHE POISONING

Review cache key and restore key matching breadth.

## 59. DEPENDENCY CACHE

Does not execute on its own, but can return attacker-modified files if the workflow trusts the cache blindly.

## 60. BUILD ARTIFACT

Integrity and trust boundaries between jobs and workflows.

## 61. ARTIFACT NAME COLLISION

A privileged workflow can download an incorrect or poisoned artifact.

## 62. RELEASE

Who has authority to trigger release workflows?

## 63. TAG-BASED RELEASE

Can an attacker create or push to a release tag ref?

## 64. TAG PROTECTION

If the repository operational model utilizes tag protection rules.

## 65. PACKAGE PUBLISH

NPM, PyPI, or container registry publications.

## 66. VERSION SOURCE

Is the published package version or name attacker-controlled?

## 67. RELEASE ASSET

Can a privileged job upload an attacker-supplied binary?

## 68. SIGNING

Which workflow accesses the code signing key?

## 69. SIGN UNTRUSTED ARTIFACT

Critical scenario:

```text
untrusted build
↓
artifact
↓
privileged signer
```

## 70. DEPLOY

Which exact job possesses production deployment authority?

## 71. DEPLOY REF

Does it deploy from:

- main

- tag

- arbitrary SHA/input

## 72. MANUAL INPUT SHA

workflow_dispatch inputs can allow an operator to deploy arbitrary commits. May be intentional, but audit access.

## 73. ENVIRONMENT URL

Not a security control.

## 74. CONCURRENCY

Production deployment workflows must prevent concurrent runs where race conditions create state corruption.

## 75. CANCEL-IN-PROGRESS

Can abort database migrations or deployments midway.

## 76. MIGRATIONS

Does the workflow run database migrations?

## 77. RETRY

Re-running GitHub Actions can repeat non-idempotent deployment or migration steps.

## 78. MANUAL RERUN

Do not assume reruns are safe.

## 79. OUTPUTS

Secrets can leak via:

- job outputs

- logs

- artifacts

## 80. MASKING

Transformed or base64-encoded secrets might not be masked in logs.

## 81. `set -x`

Can leak secrets into shell debug output.

## 82. `printenv`

Environment variable secret dump.

## 83. ERROR COMMAND

Error output may expose credentials embedded in CLI command arguments.

## 84. STEP SUMMARY

Do not write credentials into GitHub step summaries.

## 85. PR COMMENT

Workflows can inadvertently post secret tokens into public PR comments.

## 86. SARIF/REPORT

Generated vulnerability scanner reports may contain sensitive file paths or data.

## 87. PATH FILTER

Workflow security should not rely on filters that an attacker can bypass by renaming files.

## 88. BRANCH FILTER

Carefully verify branch filtering patterns.

## 89. TAG FILTER

Glob pattern semantics.

## 90. CONDITION

Complex `if:` expressions can harbor subtle logic bugs.

## 91. FORK DETECTION

Do not rely on incorrect context fields.

## 92. ACTOR VS TRIGGERING_ACTOR

Re-run semantics can alter trust evaluation.

## 93. BOT

Dependabot token and secret access restrictions.

## 94. SCHEDULE

Executes with the current default branch workflow file, not necessarily the version from a release tag.

## 95. REPOSITORY_DISPATCH

Who holds a token capable of triggering the dispatch event?

## 96. ISSUE_COMMENT DEPLOY

Comments such as `/deploy` must enforce strict actor permission validation.

## 97. ASSOCIATION

`author_association` can aid validation, but requires understanding permission semantics.

## 98. APPROVAL BOT

Do not treat automated bots as inherently trusted if an untrusted user can control their input triggers.

## 99. COMMIT PINNING

For high-privilege third-party actions, recommend full commit SHA pinning where practical.

## 100. FINDING FORMAT

```text
ID:
Severity:
Status:
Evidence tier:
Workflow:
Trigger:
Job:
Step:
Runner:
Permissions:
Secrets:
Untrusted input:
Execution path:
Impact:
Blast radius:
Evidence:
Fix:
Regression check:
Complexity:
```

## 101. EVIDENCE

```text
A - reproduced in safe repo/test
B - complete workflow execution path
C - strong YAML/config evidence
D - inferred
E - hardening
```

## 102. STATUS AND FALSE POSITIVES

Status:

- **CONFIRMED** - tier A or B evidence shows the failure or exploit path.
- **LIKELY** - tier C evidence.
- **NOT VERIFIED** - depends on runtime state, settings or versions that could not be checked (tier D). Never present tier D as confirmed.
- **NOT APPLICABLE** - the component or pattern is not used.
- **CONTROLLED** - the risk exists but another control contains it.
- **HARDENING** - improvement without a current failure path (P4).

False-positive rules:

- `pull_request_target` or `workflow_run` is not a vulnerability by itself; it becomes one when the privileged job checks out, executes or interpolates untrusted content.
- An action pinned to a tag instead of a commit SHA is HARDENING unless the action is high-privilege or its publisher is not trusted.
- Secrets referenced in a workflow are not exposed if no job reachable from untrusted triggers receives them.
- `${{ }}` expressions over trusted values (repository constants, `github.sha`, workflow inputs restricted to maintainers) are not injection points.
- Workflows in forks run with fork-scoped permissions; do not report them as affecting the base repository unless a trigger crosses that boundary.
- Branch protection, environment rules and organization settings are outside the repository; mark dependent findings **NOT VERIFIED** when they cannot be checked.

Do not report a missing best practice as a confirmed defect unless there is a concrete failure, exploit, correctness, reliability, or operational path.

## 103. SEVERITY

P0:
- untrusted PR code -> production signing/deploy/admin credential -> arbitrary production control

P1:
- expression injection in a privileged workflow
- artifact poisoning -> privileged execution
- self-hosted runner untrusted code -> internal network or secret compromise
- overbroad OIDC trust policy grants production cloud roles

P2:
- excessive `GITHUB_TOKEN` or secret scope reachable only by trusted triggers
- cache poisoning or third-party action risk without a confirmed privileged consumer
- deployment paths that bypass intended approvals for non-production environments

P3:
- limited weaknesses with narrow impact (noisy logs, minor permission excess)

P4:
- hardening without a current exploit path

## 104. OUTPUT

`GITHUB_ACTIONS_FORENSIC_AUDIT.md`

## 105. MATRICES

### Workflow Matrix

| Workflow | Trigger | Token permissions | Secrets | Deploy |
|---|---|---|---|---|

### External Action Matrix

| Action | Ref | Third-party | Secrets | Write perms |
|---|---|---|---|---|

### Trust Matrix

| Trigger | Untrusted code | Secrets | Write token | Runner |
|---|---|---|---|---|

## 106. SECOND PASS

Mandatorily test or analyze:

- malicious PR modifies package script
- PR title shell characters
- pull_request_target checkout
- workflow_run poisoned artifact
- third-party action compromise assumption
- self-hosted runner persistence
- rerun privileged workflow
- arbitrary dispatch input
- OIDC branch/subject manipulation
- production deploy concurrency

## 107. FINAL QUALITY GATE

Verify:

- all workflows
- all triggers
- effective permissions
- secrets per job
- untrusted inputs
- third-party refs
- reusable workflows
- artifacts/caches
- self-hosted runners
- OIDC
- release signing
- package publish
- production deploy
- rerun/idempotency

# FINAL RULE

I do not want:

> Pin actions and reduce permissions.

I am seeking:

```text
trigger:
pull_request_target
↓
job has:
contents: write
production token
↓
checkout:
ref = pull_request.head.sha
↓
npm install
↓
PR author modifies postinstall
↓
attacker code executes with production secret
```

or:

```text
untrusted PR workflow
↓
uploads build artifact
↓
workflow_run triggers privileged release job
↓
release job downloads artifact
↓
executes included script
↓
production signing key exposed
```

If the workflow is not production-relevant:

adjust severity accordingly.

If the issue represents only a best-practice improvement:

**P4 - HARDENING.**

可替换内容

  • {{ github.event.issue.title }}
  • {{ }}

分类与标签

编程开发、持续集成安全、供应链安全、工作流权限、密钥管理、部署授权

前往 AI 图片创作