Repository navigation
fix: limit the CI token, and make the export scan linear - #51
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The two code-scanning alerts open on
mainthat a change can close.ci.ymlran with a write-capable tokenThere was no
permissionsblock, so every job got the defaultGITHUB_TOKEN— write access to contents, issues, packages and more — handed to every third-party action and everyrun:block in the file. Nothing in this workflow writes: it checks out, installs, builds, packages and asserts.release.ymlalready does this properly (permissions: {}at the top, each job widening only what it needs), soci.ymlwas 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-permissionsalerts — they are the same finding reported at two job locations.reExportedNameswas quadratic/export\s*\{([^}]+)}\s*from/gThe class admits
{, so the body could run across any number of followingexport {sequences before failing on the closing brace. Every start position paid for the rest of the input. CodeQL called itjs/polynomial-redos, high severity.Measured here, it is exactly quadratic — 4× per doubling:
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:exportsstill reportsrenderer 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 run1147 passed / 69 files,eslint .clean,tsc --noEmitclean,actionlintclean,verify:exportspasses.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.