Skip to content

fix: limit the CI token, and make the export scan linear - #51

Merged
stuffbucket merged 1 commit into
mainfrom
fix/limit-workflow-token-and-redos
Sep 6, 2026
Merged

stuffbucket merged 1 commit into
mainfrom
fix/limit-workflow-token-and-redos

Conversation

@stuffbucket

Copy link
Copy Markdown
Owner

The two code-scanning alerts open on main that a change can close.

ci.yml ran with a write-capable token

There was no permissions block, so every job got the default GITHUB_TOKEN — write access to contents, issues, packages and more — handed to every third-party action and every run: block in the file. Nothing in this workflow writes: it checks out, installs, builds, packages and asserts.

release.yml already does this properly (permissions: {} at the top, each job widening only what it needs), so ci.yml was the outlier rather than this being a new convention.

Set at workflow level so a job added later inherits it, and a job that genuinely needs to write has to widen it where a reviewer sees the exception.

This closes both actions/missing-workflow-permissions alerts — they are the same finding reported at two job locations.

reExportedNames was quadratic

/export\s*\{([^}]+)}\s*from/g

The class admits {, so the body could run across any number of following export { sequences before failing on the closing brace. Every start position paid for the rest of the input. CodeQL called it js/polynomial-redos, high severity.

Measured here, it is exactly quadratic — 4× per doubling:

input before after
2,000 14.5 ms 0.075 ms
4,000 47.8 ms 0.080 ms
8,000 172.1 ms 0.148 ms
16,000 681.7 ms 0.259 ms

Excluding { as well fixes it, and is the more accurate pattern: an ECMAScript export clause cannot contain {, so a match that crossed one was never a single statement.

Output is unchanged — the same 60 names off the built renderer entry, and verify:exports still reports renderer JavaScript exposes only the approved component surface.

The function had no test

Six now, including the brace-crossing case and a bound on the adversarial input: 50 ms, which leaves this implementation two orders of magnitude of headroom and still fails the one it replaces by more than three times. A bound rather than a ratio, because a ratio needs a second implementation to compare against.

Verification

vitest run 1147 passed / 69 files, eslint . clean, tsc --noEmit clean, actionlint clean, verify:exports passes.

Whether CodeQL actually closes the three alerts is only knowable from the run on this PR — the reasoning above is why it should, not evidence that it did.

The two code-scanning alerts open on `main` that a change can close.

`ci.yml` had no `permissions` block, so every job ran with the default
GITHUB_TOKEN -- write access to contents, issues, packages and more, handed to
every third-party action and every `run:` block in the file. Nothing in this
workflow writes: it checks out, installs, builds, packages and asserts.
`release.yml` already does this correctly, with `permissions: {}` at the top
and each job widening what it needs, so this is the outlier rather than a new
convention. Set at workflow level so a job added later inherits it, and a job
that genuinely needs to write has to say so where a reviewer sees it.

`reExportedNames` matched `/export\s*\{([^}]+)}\s*from/`. Because the class
admits `{`, the body could run across any number of following `export {`
sequences before failing on the closing brace, so every start position paid
for the rest of the input. CodeQL called it `js/polynomial-redos`, high, and
measured on this machine it is exactly quadratic:

  input     before      after
   2,000     14.5 ms    0.075 ms
   4,000     47.8 ms    0.080 ms
   8,000    172.1 ms    0.148 ms
  16,000    681.7 ms    0.259 ms

Excluding `{` as well fixes it, and is the more accurate pattern: an
ECMAScript export clause cannot contain `{`, so a match that crossed one was
never a single statement. Output is unchanged -- the same 60 names off the
built renderer entry, and `verify:exports` still passes.

The function had no test. It has six now, including the brace-crossing case
and a bound on the adversarial input: 50 ms, which leaves this implementation
two orders of magnitude of headroom and still fails the one it replaces by
more than three times.

The third open alert, `missing-workflow-permissions` reported twice against
`ci.yml`, is the same finding at two job locations and both are closed by the
one block above.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@stuffbucket
stuffbucket merged commit 4d1e869 into main Sep 6, 2026
6 checks passed
@stuffbucket
stuffbucket deleted the fix/limit-workflow-token-and-redos branch September 8, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant