I am using the official template of SAST in my .gitlab-ci.yml
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
The pipeline runs and the Nodejsscan throws below message
[WARN] [NodeJsScan] No match in /builds/test/frontend/test-frontend
The path builds/test/frontend/test-frontend contains package.json in the top level of the repo only.
After adding the src directory also, it shows No matches
$ cd src/
$ ls
App.scss
App.test.tsx
App.tsx
assets
components
containers
environments
fonts.scss
hooks
index.scss
index.tsx
models
react-app-env.d.ts
serviceWorker.ts
services
setupTests.ts
testHelpers.ts
testsMockData.ts
variables.scss
viewModels
$ /analyzer run
[INFO] [NodeJsScan] [2024-01-30T13:11:13Z] ▶ GitLab NodeJsScan analyzer v4.1.8
[INFO] [NodeJsScan] [2024-01-30T13:11:13Z] ▶ Detecting project
[WARN] [NodeJsScan] [2024-01-30T13:11:13Z] ▶ No match in builds/test/frontend/test-frontend
How to enable the nodejscan to analyze the project
Check if this is similar to this thread, with a warning about
gl-sast-report.jsonnot being found as an artifact: it is similar to the warning you are receiving in your pipeline.gl-sast-report.jsonfile is expected to be generated by the SAST job and should be declared as an artifact for the job to capture.includestatements for SAST templates were correctly placed in the.gitlab-ci.ymlfile.gl-sast-report.jsonfile.So make sure your
.gitlab-ci.ymlis correctly configured to generate and capturegl-sast-report.json.The relevant portion (with
artifacts:reports:sast) should be:Enable
CI_DEBUG_TRACEas a variable in your job to get more verbose logs. And confirm whether the SAST job is actually generating thegl-sast-report.jsonfile. If the file is not being created, the problem might lie with the SAST scanner's operation rather than the CI/CD configuration.Make sure your JavaScript or TypeScript files are located in the directory
/builds/test/frontend/test-frontend. NodeJsScan needs to find the files it is supposed to scan. If your files are in a different directory, you will need to adjust the path in the CI/CD configuration.Check your
.gitlab-ci.ymlfile to make sure it is properly set up for NodeJsScan. The NodeJsScan job should be configured to point to the directory where your JavaScript/TypeScript files are located. For instance:NodeJsScan typically expects a
package.jsonfile in the scanned directory. Make sure this file is present and correctly set up.Try running NodeJsScan locally on your project to see if it successfully scans your files. That can help determine if the issue is with the GitLab CI/CD configuration or with the project setup itself.
To configure NodeJsScan in GitLab CI/CD to scan the JavaScript and TypeScript files located in
/builds/test/frontend/test-frontend/src, you will need to adjust the configuration in your.gitlab-ci.ymlfile: you can specify a custom script to change the working directory to thesrcfolder before running the scan. That can be done using shell commands.The
cd srccommand changes the current working directory tosrcbefore executing the NodeJsScan analyzer.Given that NodeJsScan still fails to scan the project even after correctly changing the directory to
src/, it seems the issue might be related to how NodeJsScan is recognizing the files in your project.NodeJsScan might require explicit instructions on which file patterns to scan. You can modify its command to include specific file types.
For instance, scanning all
.jsand.tsxfiles. That can be done by modifying the/analyzer runcommand to include the desired file patterns.For testing: