Potential fix for code scanning alert no. 4: Workflow does not contain permissions#11
Merged
johnpatrickroach merged 1 commit intomainfrom Mar 27, 2026
Merged
Conversation
…n permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: John Patrick Roach <johnpatrickroach1@gmail.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR updates the GitHub Actions CD workflow to explicitly restrict the default GITHUB_TOKEN to read-only access to repository contents, addressing a CodeQL code scanning alert while preserving existing publish behavior. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Potential fix for https://github.com/johnpatrickroach/better-anonymity/security/code-scanning/4
To fix this, explicitly restrict the
GITHUB_TOKENpermissions for the workflow to the minimum required. This workflow only checks out code and uploads to PyPI using a separate secret, so it does not need any write permissions fromGITHUB_TOKEN. The safest change is to setpermissions: contents: read(or evenpermissions: {}at job level), but following CodeQL’s suggestion, we will usecontents: readat the workflow root so it applies to all jobs.Concretely, in
.github/workflows/cd.yml, add apermissions:block near the top-level (alongsidenameandon). For example, insert:between the
name:line and theon:block. This does not change any functionality of the workflow: it still checks out code and publishes to PyPI exactly as before, but theGITHUB_TOKENwill now be limited to read access to repository contents, satisfying the CodeQL rule and aligning with least-privilege principles. No new imports, steps, or methods are needed.Suggested fixes powered by Copilot Autofix. Review carefully before merging.
Summary by Sourcery
CI: