Potential fixes for 2 code scanning alerts #332
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.
As part of the organization's transition to default read-only permissions for the GITHUB_TOKEN, this pull request addresses a missing permission in the workflow that triggered a code scanning alert.
This PR explicitly adds the required read permissions to align with the default read only permission and is part of a larger effort for this OKR https://github.com/github/security-services/issues/455
Potential fixes for 2 code scanning alerts from the Copilot AutoFix: Missing Permissions in Workflows security campaign:
https://github.com/github/elastomer-client/security/code-scanning/6
The best way to fix this issue is to explicitly add a
permissionsblock to the workflow to restrict the granted token permissions to exactly what the workflow needs. Given inspection of the workflow's steps—running Ruby setup, checking out code, caching, downloading, installing, and running tests—none of these steps seem to requirewriteaccess, andcontents: readshould be sufficient for basic checkout, dependency installation, and downloading. Therefore, at the workflow root (after thename:and beforeon:), add:Alternatively, this could be done at the job level, but it's best practice to use the workflow root unless finer-grained permissions are truly needed for different jobs.
Implementation details:
permissions:block after thename:line and before theon:block.https://github.com/github/elastomer-client/security/code-scanning/2
To fix this issue, add an explicit
permissionsblock to limit theGITHUB_TOKENscope to the least privilege required by the job. For a Rubocop CI job, only read access to the repository contents is needed.Specifically:
permissions: contents: readeither at the root (applies to all jobs) or underjobs.build(for just this job). The root is preferred for clarity unless you have multiple jobs needing different permissions.jobs:key (line 6) for workflow-level permissions.No imports, additional methods, or other modifications are required.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.