Fix CodeQL code scanning alerts - #87
Merged
Merged
Conversation
Alerts #1, #2, #4 (actions/missing-workflow-permissions): give each reusable-workflow caller job an explicit least-privilege permissions block, matching the existing style in codeql.yml. Because a caller's permissions are the ceiling for the called workflow, each grant covers exactly what shared-config's workflow does: - cd.yml -> contents: write. shared-config's cd.yml checks out with persisted credentials and runs publish-rubygems-action (rake release pushes the tag) followed by gh release create. - stale.yml -> issues: write + pull-requests: write. actions/stale comments on and closes both stale issues and stale PRs. - triage.yml -> issues: write. The called workflow only runs gh issue edit --add-label triage. ci.yml already declares contents: read and codeql.yml already declares its own scopes, so both are untouched. Alert #5 (rb/polynomial-redos): /#.*pack_public:\s*true/ has no anchor, so a line of many '#' characters makes the engine rerun the .* scan from every '#', which is quadratic. Only the sigil's existence matters and . never crosses a newline, so any '#' that can start a match implies the line's first '#' can too. Look up the first '#' with String#index and search from just past it, and drop the '#.*' prefix from PUBLICIZED_SIGIL_REGEX so the constant is now the whitespace-tolerant regex form of its sibling PUBLICIZED_SIGIL. Verified equivalent against the old regex over 2M randomly generated single-line inputs, and pinned the '#'-must-precede-the-sigil behaviour with new cases in the existing content_contains_sigil? test.
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.
Alerts #1, #2, #4 (actions/missing-workflow-permissions): give each
reusable-workflow caller job an explicit least-privilege permissions
block, matching the existing style in codeql.yml. Because a caller's
permissions are the ceiling for the called workflow, each grant covers
exactly what shared-config's workflow does:
persisted credentials and runs publish-rubygems-action (rake release
pushes the tag) followed by gh release create.
comments on and closes both stale issues and stale PRs.
gh issue edit --add-label triage.
ci.yml already declares contents: read and codeql.yml already declares
its own scopes, so both are untouched.
Alert #5 (rb/polynomial-redos): /#.pack_public:\strue/ has no anchor,
so a line of many '#' characters makes the engine rerun the .* scan from
every '#', which is quadratic. Only the sigil's existence matters and .
never crosses a newline, so any '#' that can start a match implies the
line's first '#' can too. Look up the first '#' with String#index and
search from just past it, and drop the '#.*' prefix from
PUBLICIZED_SIGIL_REGEX so the constant is now the whitespace-tolerant
regex form of its sibling PUBLICIZED_SIGIL. Verified equivalent against
the old regex over 2M randomly generated single-line inputs, and pinned
the '#'-must-precede-the-sigil behaviour with new cases in the existing
content_contains_sigil? test.
Alerts resolved
rb/polynomial-redos(high) —lib/packwerk/privacy/checker.rb:38actions/missing-workflow-permissions(medium) —.github/workflows/cd.yml:11actions/missing-workflow-permissions(medium) —.github/workflows/stale.yml:8actions/missing-workflow-permissions(medium) —.github/workflows/triage.yml:9Verification
permissions:block (cross-checked by parsing the YAML against the alert list).actionlintoutput is byte-identical tomain— no new findings introduced.codeql.ymluntouched.