ci: add npm audit CI check for react-frontend security#288
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a frontend-focused security audit check to CI and documents it so contributors know what to expect when touching react-frontend/.
Changes:
- Documented a React frontend security policy in contribution guidelines.
- Added a GitHub Actions workflow to run
npm audit --audit-level=highon PRs that modifyreact-frontend/**.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| docs/Contribute.md | Documents the new CI security audit behavior for react-frontend/ PRs. |
| .github/workflows/frontend-security-audit.yml | Introduces a PR-scoped workflow that installs dependencies and runs npm audit for high/critical findings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| `npm audit --audit-level=high` and will block merging if any high or | ||
| critical severity vulnerabilities are introduced. |
| 3. For issues that can't be auto-fixed, update the affected dependency | ||
| manually or open a separate issue. | ||
|
|
||
|
|
| name: Frontend Security Audit | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'react-frontend/**' |
vmuralictr
left a comment
There was a problem hiding this comment.
Thanks for adding this — automated security scanning is a great addition! A few things to address before merging:
1. Existing vulnerabilities will block all contributors immediately
The PR description mentions existing vulnerabilities will be fixed in a follow-up PR, but until then this workflow will fail for every contributor from day one. Consider resolving the existing vulnerabilities first before merging this workflow.
2. No push trigger on main branch
The workflow only triggers on pull_request. If someone with direct push access pushes to master, the audit won't run. Consider adding a push trigger:
on:
push:
branches: [master]
paths:
- 'react-frontend/**'
pull_request:
paths:
- 'react-frontend/**'3. Dev dependencies included in the audit
npm audit scans dev dependencies by default, which don't affect production users. Consider adding --omit=dev to focus only on production dependencies:
run: npm audit --audit-level=high --omit=dev4. Docs overstate enforcement
The docs say the pipeline "prevents merging" — this only happens if branch protection rules are configured to require this check. To avoid misleading contributors, consider updating the wording to: "will fail CI and may block merging when required checks are enforced"
5. Minor: trailing whitespace in Contribute.md
There are trailing spaces on the blank line before ## Note — worth cleaning up.
Overall this is a solid contribution — once the existing vulnerabilities are resolved first, this will be a great addition to the repo!
|
Hi @TusharB-07 , just following up on the review comments left last week. Could you please take a look when you get a chance? Happy to help if you have any questions on the feedback! |
Signed-off-by: TusharB-07 <tusharnbiswas07@gmail.com>
- fix existing moderate vulnerabilities via npm audit fix - add push trigger on master branch to workflow - add --omit=dev flag to npm audit command - add permissions: contents: read to workflow - fix Contribute.md wording (fail CI, not block merging) - remove trailing whitespace in Contribute.md Signed-off-by: TusharB-07 <tusharnbiswas07@gmail.com>
5ce67c8 to
847fbff
Compare
|
Hi @vmuralictr, thanks for the detailed review I've addressed all five points:
Also added |
vmuralictr
left a comment
There was a problem hiding this comment.
This PR has one critical blocker: react-scripts@0.0.0 in package.json is an empty placeholder package that will break all build scripts (npm start, npm run build, npm test). Please revert to "5.0.1".
Additional issues noted in inline comments:
- The audit will permanently fail from day one since react-scripts 5.0.1 already has known high/critical vulnerabilities — existing issues need to be fixed first
- --omit=dev flag skips dev dependency audits
- Workflow won't self-trigger when its own file changes
Also note there are merge conflicts that need to be resolved before this can be merged.
| "react-paginate": "^8.2.0", | ||
| "react-router-dom": "^6.30.3", | ||
| "react-scripts": "5.0.1", | ||
| "react-scripts": "^0.0.0", |
There was a problem hiding this comment.
react-scripts@0.0.0 is an empty placeholder on npm with no build scripts or dependencies. This will break npm start, npm run build, and npm test. Please revert to "5.0.1".
| - 'react-frontend/**' | ||
| pull_request: | ||
| paths: | ||
| - 'react-frontend/**' |
There was a problem hiding this comment.
The paths filter doesn't include the workflow file itself, so changes to this workflow won't trigger the audit. This PR cannot self-verify. Consider adding .github/workflows/frontend-security-audit.yml to the paths list.
| run: npm ci | ||
|
|
||
| - name: Run security audit | ||
| run: npm audit --audit-level=high --omit=dev |
There was a problem hiding this comment.
--omit=dev skips auditing devDependencies. Vulnerabilities in build-time tools won't be caught. Consider removing this flag for full coverage, or add a comment explaining why dev vulnerabilities are intentionally excluded.
| ## Security Policy for React Frontend | ||
|
|
||
| All pull requests that modify files under `react-frontend/` are subject | ||
| to an automated security audit via GitHub Actions. The CI pipeline runs `npm audit --audit-level=high` and will fail CI if any high or |
There was a problem hiding this comment.
The docs say the CI "will fail if any high or critical vulnerabilities are introduced", but the workflow flags all existing ones too. Since react-scripts 5.0.1 already has known high/critical vulns, every PR touching react-frontend/ will fail CI immediately. Please fix existing vulnerabilities first or update the wording to reflect the actual behavior.
Closes #285
What this does
.github/workflows/frontend-security-audit.ymlthat runsnpm audit --audit-level=highon every PR touchingreact-frontend/docs/Contribute.mdWhy
Without a CI gate, npm vulnerabilities can silently re-accumulate.
This makes security enforcement automatic going forward.
Notes
Existing vulnerabilities in the repo will need to be addressed
in a follow-up PR. This PR only adds the enforcement gate as
requested in #285.