Potential fixes for 3 code scanning alerts #328
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 fixes for 3 code scanning alerts from the Copilot AutoFix: Missing Permissions in Workflows security campaign:
https://github.com/github/catalyst/security/code-scanning/5
To fix the problem, we should add a
permissions:block specifying the minimal necessary permissions for the job. In this case, the workflow only interacts with npm (publishing to it), and reads from the repository (checking out code, reading package.json, etc.), socontents: readis sufficient. This block should be placed either at the root of the workflow or at thepublish-npmjob level. For clarity and ease, placing it at the workflow root is recommended, so all jobs inherit least privilege unless otherwise specified. No other changes or imports are necessary.https://github.com/github/catalyst/security/code-scanning/4
To fix the problem, add a
permissionsblock specifying the least privilege required at either the workflow or the job level. Since the whole workflow does not appear to perform any operations requiring write permissions (e.g. status updates, PR creation, etc.), settingpermissions: contents: readat the workflow (top) level is recommended. This will apply to all jobs in the workflow, ensuring they cannot modify repository contents or metadata through GITHUB_TOKEN unless specifically required and overridden. Edit.github/workflows/nodejs.yml: insert thepermissions:block after thenameline and beforeon:.https://github.com/github/catalyst/security/code-scanning/3
The problem is best fixed by adding an explicit
permissionsblock with the least privilege required for the workflow at the top level of the workflow YAML (right after thenamekey, beforeon:). This will ensure all jobs inherit the desired permission restrictions unless overridden. Given the context (documentation build and Lighthouse CI),contents: read(the minimum) looks sufficient. If more permissions are needed in the future, they can be added as required.To implement the fix:
.github/workflows/lighthouse.yml.permissions:block withcontents: readafter thename:statement.Suggested fixes powered by Copilot Autofix. Review carefully before merging.