Skip to content

Commit 6d5ab73

Browse files
committed
implement NPM
Signed-off-by: Jefferson <jefferson.rios.caro@gmail.com>
1 parent 6b6f5d4 commit 6d5ab73

3 files changed

Lines changed: 75 additions & 4 deletions

File tree

.github/workflows/check-vulns.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,36 @@ jobs:
8787
max-parallel: 1
8888
steps:
8989
- uses: actions/checkout@v4
90+
- name: Build labels for issue
91+
id: build_labels
92+
run: |
93+
# Start with base labels
94+
LABELS="${{ inputs.nsolidStream }}"
95+
96+
# Add NPM label if it's an npm vulnerability
97+
if [ "${{ matrix.vulnerabilities.source }}" = "npm" ]; then
98+
LABELS="${LABELS}, NPM"
99+
fi
100+
101+
# Add severity label if available
102+
if [ -n "${{ matrix.vulnerabilities.severity }}" ] && [ "${{ matrix.vulnerabilities.severity }}" != "null" ]; then
103+
SEVERITY=$(echo "${{ matrix.vulnerabilities.severity }}" | tr '[:lower:]' '[:upper:]')
104+
LABELS="${LABELS}, ${SEVERITY}"
105+
fi
106+
107+
# Extract runtime version from stream (e.g., node-v20.x-nsolid-v5.x -> v20.x)
108+
RUNTIME_VERSION=$(echo "${{ inputs.nsolidStream }}" | sed -n 's/.*node-\(v[0-9]*\.x\).*/\1/p')
109+
if [ -n "$RUNTIME_VERSION" ]; then
110+
LABELS="${LABELS}, ${RUNTIME_VERSION}"
111+
fi
112+
113+
echo "ISSUE_LABELS=${LABELS}" >> $GITHUB_ENV
114+
echo "Generated labels: ${LABELS}"
90115
- uses: dblock/create-a-github-issue@v3
91116
with:
92117
update_existing: false
93118
search_existing: open
94-
labels: ${{ matrix.vulnerabilities.source == 'npm' && format('{0}, NPM', inputs.nsolidStream) || inputs.nsolidStream }}
119+
labels: ${{ env.ISSUE_LABELS }}
95120
env:
96121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97122
VULN_ID: ${{ matrix.vulnerabilities.id }}

dep_checker/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from gql.transport.aiohttp import AIOHTTPTransport
2323
from nvdlib import searchCVE # type: ignore
2424
from packaging.specifiers import SpecifierSet
25-
from typing import Optional
25+
from typing import Optional, List
2626
from pathlib import Path
2727

2828
import json

dep_checker/npm_audit.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,42 @@
1515

1616
logger = logging.getLogger(__name__)
1717

18+
# Folder paths to exclude from npm package scanning
19+
# Add folder paths here that should be skipped during package.json discovery
20+
# Paths should be relative to the repository root (e.g., "deps/v8/tools/turbolizer")
21+
# You can also use folder names for broader exclusions (e.g., "test" excludes all test folders)
22+
EXCLUDE_PATHS = [
23+
# Specific path exclusions
24+
"deps/v8/tools/turbolizer",
25+
26+
# General folder name exclusions (will match any folder with this name)
27+
"test",
28+
"tests",
29+
"examples",
30+
"example",
31+
"docs",
32+
"documentation",
33+
"demo",
34+
"demos",
35+
"coverage",
36+
".git",
37+
".github"
38+
]
39+
1840

1941
class NPMAuditChecker:
2042
"""Handles npm audit vulnerability checking for package.json files"""
2143

2244
def __init__(self, repo_path: Path, timeout: int = 300):
2345
self.repo_path = repo_path
2446
self.timeout = timeout
47+
self.exclude_paths = EXCLUDE_PATHS # Use the static exclusion list
2548

2649
def find_package_json_files(self) -> List[Path]:
27-
"""Find all package.json files in the deps/ folder only"""
50+
"""Find all package.json files in the deps/ folder only, excluding specified folders"""
2851
package_json_files = []
52+
excluded_count = 0
53+
2954
try:
3055
# Only search within the deps/ folder
3156
deps_path = self.repo_path / "deps"
@@ -36,9 +61,30 @@ def find_package_json_files(self) -> List[Path]:
3661
# Use pathlib to recursively find package.json files in deps/ folder
3762
for package_json in deps_path.rglob("package.json"):
3863
# Skip node_modules directories
39-
if "node_modules" not in str(package_json):
64+
if "node_modules" in str(package_json):
65+
continue
66+
67+
# Check if the package.json is in an excluded path
68+
is_excluded = False
69+
package_relative_path = str(package_json.relative_to(self.repo_path))
70+
71+
for exclude_path in self.exclude_paths:
72+
# Check for exact path match or if path starts with the exclusion
73+
if (package_relative_path.startswith(exclude_path + "/") or
74+
package_relative_path == exclude_path or
75+
exclude_path in package_json.parts): # Also support folder name matching
76+
is_excluded = True
77+
excluded_count += 1
78+
logger.debug(f"Excluding {package_json} (matches exclusion: {exclude_path})")
79+
break
80+
81+
if not is_excluded:
4082
package_json_files.append(package_json)
83+
4184
logger.info(f"Found {len(package_json_files)} package.json files in deps/ folder")
85+
if excluded_count > 0:
86+
logger.info(f"Excluded {excluded_count} package.json files based on exclusion list: {self.exclude_paths}")
87+
4288
return package_json_files
4389
except Exception as e:
4490
logger.error(f"Error finding package.json files in deps/ folder: {e}")

0 commit comments

Comments
 (0)