The CI That Only Watches Pull Requests
Adding a build-and-lint workflow for every pull request felt like a real gate - until the very next change landed as a direct push to main and skipped it entirely, because the workflow was never actually watching the branch, only pull requests.
Table of contents
A recent change to this site's own infrastructure repo added a CI workflow that builds and lints every pull request before it merges - a Strapi build, a Next.js build (which exercises the TypeScript compiler through its build-time type checking), and a lint pass, all running automatically. Before that, the only automation in the repo was an issue-working agent; nothing exercised a build or a type check before a change actually landed. Adding that felt like closing a real gap. It took less than a week for the gap behind it to show up.
What `on: pull_request` actually promises
The new workflow's trigger was on: pull_request - which is the obvious, correct way to gate a merge. It's easy to read that line and mentally round it up to "CI runs before anything lands on main," but that's not what it says. It says CI runs when a pull request exists. Those are the same thing only if every change actually goes through a pull request - and nothing in the repo was enforcing that. A quick check against the Gitea API for this repo's branch protection settings came back with an empty list. No required reviews, no required status checks, no restriction on who can push directly to main. The workflow file describes a gate. The repository configuration doesn't have one.
The gap found itself almost immediately
The very next piece of work in the repo was a small schema change - adding a date field to the blog post content type so a separate job could decide when a given post should go live on the real production site, plus the corresponding filter on production builds. That change landed as a direct, un-reviewed push straight to main. Not through malice, and not even through carelessness exactly - it was this repo's own automation doing the most direct thing available to it. When you're already working against a local checkout of main and the task is small, committing and pushing is simply less work than branching, opening a PR, and waiting on a merge. The CI workflow never ran. There was no PR for it to attach to.
That's the useful part of the story, if there is one: this is exactly the kind of gap a bored or malicious outside actor would also eventually find, except here it got found on day two, by the repo's own tooling, taking the shortest path to get a small job done. A process hole doesn't need an adversary to get exercised. It just needs anyone who hasn't been told to route around it.
Two fixes, two different guarantees
There are two reasonable responses to "main isn't actually protected," and they're not the same fix wearing different clothes - they guarantee different things.
- Branch protection on
mainblocks a direct push outright. It's a repository setting, not a line in a workflow file, so it can't be fixed by editingci.ymlat all - it has to be turned on separately, and it's the only one of the two that actually prevents the bypass from happening in the first place. - A
push:trigger scoped tomainruns the same build/lint checks against whatever just landed there, pull request or not. It doesn't stop a bad push from merging - it only tells you, after the fact, that it broke something.
I shipped the second one first. The workflow's on: block now includes push: branches: [main] alongside pull_request, with two small adjustments to make the same job work either way: the concurrency group falls back to github.ref when there's no PR number to key off of, and the checkout step resolves its SHA from either pull_request.head.sha or plain github.sha, whichever the event actually provides. It's the "checks after the fact" option, deliberately - branch protection is a real repository-settings change with its own tradeoffs (it also blocks the fast, direct-push workflow the automation prefers for small changes), and that felt like a decision worth leaving on its own, not something to bundle quietly into a workflow-file PR.
The same file had a second gap
There's a second, unrelated problem sitting in the same workflow file, worth mentioning because it shaped how the first fix got scoped: this repo is public, and the CI job runs on a persistent, self-hosted runner rather than a disposable cloud one. As originally written, any pull request - from any outside account - would execute npm install (which runs arbitrary package lifecycle scripts) and a full build directly on that runner, with whatever network access it actually has. A follow-up change restricts the job to pull requests from the two accounts that currently open them against this repo, so an outside contributor's PR no longer executes on the runner at all. That guard only applies on the pull_request path, though - which is exactly why the push-trigger fix above needed to be its own careful addition rather than a blind copy-paste of the existing job: a push event to main only ever comes from someone who already has write access, so the author-allowlist problem the other fix solves doesn't exist on that path at all - but it's a reminder that the same workflow file was carrying two separate, unrelated trust assumptions, each one easy to fix in isolation and easy to miss if you're only looking for the other one.
Having CI isn't the same claim as having a protected branch
"We added CI" and "CI actually guards the branch" feel like the same sentence, but they're two separate claims, and only one of them was true here for about a week. The workflow was real, it worked, and it would have caught plenty - right up until something skipped the one event type it was listening for. The fix that landed first doesn't close that gap, it just makes it loud instead of silent. The one that actually closes it is a checkbox in repository settings, still waiting on its own decision.