Align alphaNumericRegex() with the documented grouped SHA pattern#21838
Open
Copilot wants to merge 7 commits into
Open
Align alphaNumericRegex() with the documented grouped SHA pattern#21838Copilot wants to merge 7 commits into
alphaNumericRegex() with the documented grouped SHA pattern#21838Copilot wants to merge 7 commits into
Conversation
Copilot created this pull request from a session on behalf of
owen-mc
May 12, 2026 13:03
View session
f1a085e to
954b1c4
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the GitHub Actions analysis to recognize pinned commit refs that use either 40-hex (SHA-1) or 64-hex (SHA-256) formats, and aligns the Bash regex-detection helper with the grouped/optional form documented in QLDoc so sanitization patterns are correctly recognized.
Changes:
- Updated the pinned-commit matching regex to accept 40 or 64 hex characters (via an optional 24-hex suffix group).
- Expanded the Bash
alphaNumericRegex()helper to recognize grouped and optional quantified alphanumeric-regex checks. - Updated/added regression fixtures, expected outputs, snippet example, and change notes to reflect the new behavior.
Show a summary per file
| File | Description |
|---|---|
| actions/ql/lib/codeql/actions/Bash.qll | Updates the helper that recognizes “alphanumeric-only” Bash regex validations, including grouped/optional forms. |
| actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql | Expands what the query considers a “pinned commit” reference (40 or 64 hex). |
| actions/ql/examples/snippets/uses_pinned_sha.ql | Updates the example to match the new 40-or-64 hex pinned-SHA regex shape. |
| actions/ql/test/query-tests/Security/CWE-829/.github/workflows/unpinned_tags.yml | Adds fixtures for 64-hex pinned, 40-hex pinned regression, and invalid-length hex refs. |
| actions/ql/test/query-tests/Security/CWE-829/UnpinnedActionsTag.expected | Updates expected results to include a newly-flagged invalid-length hex ref case. |
| actions/ql/test/query-tests/Security/CWE-829/UntrustedCheckoutCritical.expected | Updates expected edges to match the adjusted test fixture structure. |
| actions/ql/src/change-notes/2026-05-12-sha256-pinned-actions.md | Adds a change note for recognizing 64-character pinned refs in actions/unpinned-tag. |
| actions/ql/lib/change-notes/2026-05-12-improved-alphanumeric-regex.md | Adds a change note for broader recognition of Bash alphanumeric validation regexes. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Bug Fix
The
alphaNumericRegex()helper inactions/ql/lib/codeql/actions/Bash.qllno longer matched the regex shape documented in the QLDoc after the pinned-SHA example was widened to support either 40 or 64 hex characters. This caused the implementation and documentation to diverge for grouped and optional quantified forms.What was the bug?
alphaNumericRegex()only matched a single character class followed by one quantifier:^[0-9]+$^[A-Za-z0-9_]{40}$^[0-9a-zA-Z]{40}([0-9a-zA-Z]{24})?$How did you fix it?
Expanded accepted regex structure
alphaNumericRegex()to build up the accepted pattern in stages:+or{n})?^and$Kept the helper aligned with the QLDoc example
([0-9a-zA-Z]{24})?, which is the shape used by the updated pinned-SHA example.Minor cleanup
Example
alphaNumericRegex()now matches patterns of this form: