For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cicd-github-script-block-injection.md.
A documentation index is available at /llms.txt.
GitHub Actions steps that run arbitrary JavaScript via actions/github-script must not incorporate untrusted event fields into their script blocks because attackers can inject content that leads to code injection or unauthorized API calls and potentially exfiltrate secrets. Check workflow steps where uses starts with actions/github-script and ensure the with.script value does not reference user-controlled GitHub context properties such as github.event.pull_request.*, github.event.issue.*, github.event.comment.*, github.event.discussion.*, or github.event.workflow_run.*; steps whose script contains these patterns will be flagged. If processing event data is required, validate and sanitize inputs, restrict workflow permissions (avoid pull_request_target when running untrusted content), or perform parsing in a hardened action or external service with least privilege. For the pull_request trigger, the vulnerable fields are much more significant when the change comes from a fork.
Secure example that avoids using event fields:
- name:Safe scriptuses:actions/github-script@v6with:script:| core.info('No user-controlled event data used.')
name:Composite action with github-scriptdescription:Composite action that runs github-script with untrusted issue bodyruns:using:compositesteps:- name:Run scriptuses:actions/github-script@v7with:script:| const body = `${{ github.event.issue.body }}`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thanks for reporting!'
})
name:Composite action with github-script using inputsdescription:Composite action that runs github-script with attacker-controlled composite inputsinputs:message:description:Message provided by the callerrequired:trueruns:using:compositesteps:- name:Run scriptuses:actions/github-script@v7with:script:| const body = `${{ inputs.message }}`;
core.info(body);
1
2
rulesets:- CICD / GitHub # Rules to enforce / GitHub.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.