Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/prevent dynamic scan from triggering npm audit #957

Merged
merged 4 commits into from
Mar 12, 2025

Conversation

feba-rajan
Copy link
Contributor

@feba-rajan feba-rajan commented Mar 12, 2025

Preview Link

https://submit-pr-[PR_NUMBER].herokuapp.com/

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

This PR ensures that the dynamic security scan (ZAP scan) does not trigger npm audit, which is meant for static security scanning.

Related Tickets & Documents

  • Ticket Link: ticket
  • Related Issue #: main ticket
  • Closes #: closed pr

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: No application code has been changed
  • I need help with writing tests

QA sign off

  • Code has been checked and approved
  • Design has been checked and approved
  • Product and business logic has been checked and proved

[optional] Are there any post-deployment tasks we need to perform?

[optional] Are there any dependencies on other PRs or Work?

Summary by CodeRabbit

  • Chores
    • Enhanced security scanning routines to ensure a more robust build process by handling errors gracefully.
    • Simplified the scanning procedure to reduce complexity and streamline operations.
    • Introduced a new job in the workflow to dynamically determine available environments for improved flexibility.
    • Updated the method of running security scans to improve output management.

Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

Walkthrough

The changes update the security scanning commands defined in the package.json file. The static-security-scan script now includes error handling by appending || true, ensuring the command does not fail the build. The scan:zap script has been simplified to only run the docker-security-scan command, eliminating the previous execution of static-security-scan. Additionally, a new job named detect-environments has been added to the GitHub Actions workflow to dynamically determine the environment for security audits.

Changes

File Change Summary
package.json Modified the static-security-scan command to append `
.github/workflows/security-scan.yml Added a new job detect-environments to retrieve available environments; updated dynamic-audit and static-audit jobs to use dynamic environment output; modified static-audit to call npm run static-security-scan and output results to a markdown file.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant ScanZap as scan:zap
    participant DockerScan as docker-security-scan
    participant StaticScan as static-security-scan

    Developer->>ScanZap: Execute scan:zap
    ScanZap->>DockerScan: Run docker-security-scan
    Note over ScanZap: Previous flow also invoked static-security-scan
Loading

Possibly related PRs

  • Security scan fix #819: The changes in the main PR are related to the modifications in the static-security-scan script, which is also referenced in the retrieved PR's updates to the static-audit job, as it now calls npm run static-security-scan.
  • LPA validator frontend security scan #760: The changes in the main PR, specifically the modifications to the static-security-scan script in package.json, are directly related to the updates in the static-audit job of the retrieved PR, which now calls npm run static-security-scan.

Suggested reviewers

  • DilwoarH
  • cpcundill

Poem

I'm a rabbit with a bounce so light,
Hop-ping through changes in the night,
Package commands now swift and clear,
Security scans that bring no fear,
With a twitch of ear and joyful cheer,
I celebrate each update here!
🐇🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ca1b56 and 7bacaf3.

📒 Files selected for processing (1)
  • .github/workflows/security-scan.yml (3 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/security-scan.yml

19-19: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


30-30: property "detect-environments" is not defined in object type {}

(expression)


78-78: property "detect-environments" is not defined in object type {}

(expression)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run-tests / test
🔇 Additional comments (3)
.github/workflows/security-scan.yml (3)

28-30: Review Dynamic Audit Job’s Environment Assignment
The dynamic-audit job now sets its environment using ${{ needs.detect-environments.outputs.environments }}. Please confirm that the output is correctly formatted (as a single string) because GitHub Actions’ environment property usually expects a singular environment name rather than an array.

🧰 Tools
🪛 actionlint (1.7.4)

30-30: property "detect-environments" is not defined in object type {}

(expression)


76-79: Assess Static Audit Job’s Dynamic Environment Setting
Similar to the dynamic audit job, the static-audit job uses the dynamic output for its environment (line 78). Ensure that the value from detect-environments is valid and in the expected format for a job environment to avoid misconfigurations.

🧰 Tools
🪛 actionlint (1.7.4)

78-78: property "detect-environments" is not defined in object type {}

(expression)


92-94: Confirm Static Security Scan Command Behaviour
The static-audit job now replaces the previous npm audit -f markdown call with npm run static-security-scan (line 93), which should handle errors via the appended || true in the script. Please verify that this change prevents critical failures without masking severe audit issues, aligning with the PR objective of preventing the dynamic scan from triggering npm audit.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Mar 12, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 67.43% 5613 / 8323
🔵 Statements 67.43% 5613 / 8323
🔵 Functions 63.78% 236 / 370
🔵 Branches 79.63% 735 / 923
File CoverageNo changed files found.
Generated in workflow #954 for commit c05cff2 by the Vitest Coverage Report Action

ssadhu-sl
ssadhu-sl previously approved these changes Mar 12, 2025
Copy link
Contributor

@ssadhu-sl ssadhu-sl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
.github/workflows/security-scan.yml (1)

208-208: 💡 Verification agent

❓ Verification inconclusive

Undefined Output "result" in Audit Error Check Condition
In the check-audit-errors job (line 208), the condition uses contains(join(needs.*.result, ','), 'failure'). However, none of the preceding jobs define an output named result. This discrepancy means the condition for sending a failure notification might never be triggered as intended. Please update the condition to reference valid output parameters or define the missing result output in the relevant jobs.


Action Required: Correct the Output Reference in the Workflow Condition
The condition at line 208 of .github/workflows/security-scan.yml currently uses

if: always() && contains(join(needs.*.result, ','), 'failure')

which references an output named result that is not defined in any of the preceding jobs. To ensure that failure notifications are triggered as intended, please either update the condition to reference a valid output parameter from the relevant jobs, or define the result output in those jobs if it was intended to be produced.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ee678d and 5ca1b56.

📒 Files selected for processing (1)
  • .github/workflows/security-scan.yml (3 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/security-scan.yml

14-14: "steps" section is missing in job "jobs"

(syntax-check)


14-14: "runs-on" section is missing in job "jobs"

(syntax-check)


14-14: "jobs" job should not be empty. please remove this section if it's unnecessary

(syntax-check)


20-20: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


31-31: property "detect-environments" is not defined in object type {}

(expression)


79-79: property "detect-environments" is not defined in object type {}

(expression)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run-tests / test
🔇 Additional comments (2)
.github/workflows/security-scan.yml (2)

79-79:

❓ Verification inconclusive

Validate Static Audit Job "environment" Reference
Similarly, the static-audit job uses ${{ needs.detect-environments.outputs.environments }} for its environment. Ensure that this output is in the expected format (a single string) and that it correctly resolves after the workflow structure is fixed.


Review Comment Verification: Check "environment" Output Format

After reviewing the workflow snippet, please verify that the output from the detect-environments job—referenced as ${{ needs.detect-environments.outputs.environments }}—consists of a single, properly formatted string. If the output may potentially contain multiple values or an unexpected format after the workflow structure changes, you may need to adjust the configuration for the static-audit job accordingly.

  • Confirm that the detect-environments job correctly sets the environments output as a single string.
  • If a different format is returned, update the static-audit environment reference to ensure consistency.
🧰 Tools
🪛 actionlint (1.7.4)

79-79: property "detect-environments" is not defined in object type {}

(expression)


31-31:

❓ Verification inconclusive

Validate Dynamic Audit Job "environment" Reference
The dynamic-audit job assigns its environment field with ${{ needs.detect-environments.outputs.environments }}. Please verify that after refactoring the redundant nested "jobs:" key, the output from the detect-environments job exists and is a single valid string rather than an array—since the environment property requires a single environment name.


Below are two new shell scripts to verify that the output from the detect-environments job is defined correctly as a single valid string. The first script searches for the file where the detect-environments job is defined; the second inspects that file’s outputs block for the environments key.

Please run these scripts and share the results so we can confirm whether the value is indeed a string (as required by the environment property) rather than an array.

Script 1 – Locate the detect-environments job definition:

#!/bin/bash
# Search for the definition of the 'detect-environments' job within .github/workflows.
rg -n "id:\s*detect-environments" .github/workflows

Script 2 – Inspect the outputs block for the 'environments' key:

#!/bin/bash
# Once the file is located, inspect its outputs block for the 'environments' key.
file=$(rg -l "id:\s*detect-environments" .github/workflows | head -n 1)
if [[ -n "$file" ]]; then
  echo "Inspecting outputs in file: $file"
  awk '/outputs:/ {flag=1; next} flag && /environments:/ {print; flag=0}' "$file"
else
  echo "No detect-environments job found."
fi

Please run these and update the verification results accordingly.

🧰 Tools
🪛 actionlint (1.7.4)

31-31: property "detect-environments" is not defined in object type {}

(expression)

Comment on lines 14 to 28
jobs:
detect-environments:
runs-on: ubuntu-latest
outputs:
environments: ${{ steps.environments.outputs.result }}
steps:
- uses: actions/github-script@v6
id: environments
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment];
const { data: { environments } } = await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`);
return environments.map(e => e.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Redundant Nested "jobs:" Key
The workflow contains a nested "jobs:" entry (lines 14–15) inside the top-level "jobs:" block. This extra nesting is not valid according to GitHub Actions schema and may cause the workflow to misinterpret your job definitions. Please remove the redundant "jobs:" key so that your job definitions (e.g. detect-environments) are direct children of the top-level "jobs:" key.

🧰 Tools
🪛 actionlint (1.7.4)

14-14: "steps" section is missing in job "jobs"

(syntax-check)


14-14: "runs-on" section is missing in job "jobs"

(syntax-check)


14-14: "jobs" job should not be empty. please remove this section if it's unnecessary

(syntax-check)


20-20: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Comment on lines +20 to +28
- uses: actions/github-script@v6
id: environments
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment];
const { data: { environments } } = await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`);
return environments.map(e => e.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update GitHub Script Action Version
The actions/github-script@v6 action is reported by static analysis as being outdated for current GitHub Actions runners. Consider updating to a newer version (e.g. v6.1.0 or later) to benefit from improvements and ensure compatibility.

🧰 Tools
🪛 actionlint (1.7.4)

20-20: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

@eveleighoj eveleighoj temporarily deployed to submit-pr-957 March 12, 2025 16:29 Inactive
@rosado rosado merged commit 942754b into main Mar 12, 2025
5 checks passed
@rosado rosado deleted the lpa-validator-frontend-security-scan branch March 12, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants