Skip to content

Commit 05c37ec

Browse files
ci(global): introduce semgrep code scan (#23)
* ci(global): introduce semgrep code scan * ci(global): fix semgrep util * ci(global): allow semgrep metrics * ci(global): add artifacts * ci(global): try CI instead of scan * ci(global): test file * ci(global): finalize * ci(global): analyzed semgrep findings * ci(global): add bash shebang * ci(global): remove redundant node versioning for LTS * ci(global): remove redundant node versioning for LTS
1 parent 7af2929 commit 05c37ec

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed

.github/workflows/nodejs.packages.ci.yml

+23-16
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,37 @@ on:
88

99
jobs:
1010
lint:
11-
name: Lint the code
11+
name: Lint code
1212

1313
runs-on: ubuntu-22.04
1414

15-
strategy:
16-
matrix:
17-
node-version: [ 22.x ]
18-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases
19-
2015
steps:
2116
- name: Checkout code
2217
uses: actions/checkout@v4
2318

2419
- name: Setup Node.js environment
2520
uses: actions/setup-node@v4
2621
with:
27-
node-version: ${{ matrix.node-version }}
2822
cache: 'yarn'
2923

3024
- name: Install dependencies
3125
run: yarn --immutable
3226

33-
- name: Lint the code
27+
- name: Lint source code
3428
run: yarn lint
3529

3630
audit:
37-
name: Audit the code
31+
name: Audit dependencies
3832

3933
runs-on: ubuntu-22.04
4034

41-
strategy:
42-
matrix:
43-
node-version: [ 22.x ]
44-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases
45-
4635
steps:
4736
- name: Checkout code
4837
uses: actions/checkout@v4
4938

5039
- name: Setup Node.js environment
5140
uses: actions/setup-node@v4
5241
with:
53-
node-version: ${{ matrix.node-version }}
5442
cache: 'yarn'
5543

5644
- name: Install dependencies
@@ -59,6 +47,25 @@ jobs:
5947
- name: Run dependencies audit
6048
run: yarn npm audit --all
6149

50+
semgrep:
51+
name: Audit source code
52+
53+
runs-on: ubuntu-22.04
54+
55+
container:
56+
image: semgrep/semgrep
57+
58+
if: (github.actor != 'dependabot[bot]')
59+
60+
permissions:
61+
security-events: write
62+
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
67+
- name: Run semgrep scan
68+
run: ./bin/run-semgrep.sh
6269

6370
build:
6471
name: Build and Test packages
@@ -83,7 +90,7 @@ jobs:
8390
- name: Install dependencies
8491
run: yarn --immutable
8592

86-
- name: Build the repo
93+
- name: Build repo
8794
run: yarn build
8895

8996
- name: Run tests

bin/run-semgrep.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
export SEMGREP_RULES="
4+
p/default
5+
p/javascript
6+
p/typescript
7+
p/nodejs
8+
p/comment
9+
p/cwe-top-25
10+
p/r2c-security-audit
11+
p/owasp-top-ten
12+
p/gitleaks
13+
p/secrets
14+
"
15+
16+
semgrep scan --error --metrics off

packages/configs/rollup.js

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ function typePipe(input, output, opts = {}) {
7171
entries: [
7272
{
7373
find: '@',
74+
// NOTE: Part of logic
75+
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
7476
replacement: path.resolve('./dist/dts', opts.typesDir || '.'),
7577
},
7678
],

packages/git/src/utils/tags.ts

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export function getTagRegex(packageNames: ReadonlyArray<string>, tagFormat = DEF
8181
}
8282
})
8383

84+
// NOTE: Regexp is escaped, so its not possible to create ReDOS
85+
// nosemgrep: javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp
8486
return new RegExp(`^${escapedParts.join('')}$`)
8587
}
8688

packages/mono-pub/src/utils/deps.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import type { DirResult } from 'tmp'
99
import type { BasePackageInfo, LatestPackagesReleases, PackageVersion } from '@/types'
1010

1111
function writePackageJson(obj: Record<string, unknown>, packagePath: string, cwd: string) {
12+
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
1213
fs.mkdirSync(path.join(cwd, packagePath), { recursive: true })
14+
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
1315
fs.writeFileSync(path.join(cwd, packagePath, 'package.json'), JSON.stringify(obj, null, 2))
1416
}
1517

packages/mono-pub/src/utils/path.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export async function getAllPackages(paths: Array<string>, cwd: string): Promise
2929
fileNames.push(match.fullpath())
3030
} else if (match.isDirectory()) {
3131
const fullPath = match.fullpath()
32+
// NOTE: Repo traversal is a part of package logic
33+
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
3234
const pkgPath = path.join(fullPath, 'package.json')
3335
if (fs.existsSync(pkgPath)) {
3436
fileNames.push(pkgPath)

0 commit comments

Comments
 (0)