Skip to content

Commit a67bf5d

Browse files
committed
Update CI configuration and harden Jest resolver
- Upgrade GitHub Action versions (checkout v6, setup-node v6, cache v5) - Add .NET 8 SDK to CI for MinVer versioning support - Define explicit GHA permissions (contents: read, packages: write) - Add path traversal validation to jest-resolver.cjs to ensure imports remain within the package root
1 parent 1ddbe9a commit a67bf5d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Build
22
on: [push, pull_request]
33

4+
permissions:
5+
contents: read
6+
packages: write
7+
48
jobs:
59
build:
610
runs-on: ${{ matrix.os }}
@@ -15,21 +19,25 @@ jobs:
1519
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}
1620
steps:
1721
- name: Checkout
18-
uses: actions/checkout@v4
22+
uses: actions/checkout@v6
1923
with:
2024
fetch-depth: 0
2125
- name: Build Reason
2226
run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"
2327
- name: Setup Node.js environment
24-
uses: actions/setup-node@v4
28+
uses: actions/setup-node@v6
2529
with:
2630
node-version: ${{ matrix.node_version }}
2731
registry-url: "https://registry.npmjs.org"
2832
- name: Cache node_modules
29-
uses: actions/cache@v4
33+
uses: actions/cache@v5
3034
with:
3135
path: node_modules
3236
key: ${{ matrix.node_version }}-${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
37+
- name: Setup .NET SDK for MinVer
38+
uses: actions/setup-dotnet@v5
39+
with:
40+
dotnet-version: "8.0.x"
3341
- name: Set Min Version
3442
uses: Stelzi79/action-minver@3.0.1
3543
id: version
@@ -55,7 +63,7 @@ jobs:
5563
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
5664
- name: Setup GitHub CI Node.js environment
5765
if: github.event_name != 'pull_request' && matrix.os == 'ubuntu-latest'
58-
uses: actions/setup-node@v4
66+
uses: actions/setup-node@v6
5967
with:
6068
node-version: ${{ matrix.node_version }}
6169
registry-url: "https://npm.pkg.github.com"

jest-resolver.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ module.exports = (request, options) => {
2121
if (base) {
2222
const prefix = base.replace("*", "");
2323
const suffix = request.slice(2);
24-
const resolved = path.join(packageRoot, prefix, suffix);
24+
if (suffix.includes("..") || path.isAbsolute(suffix)) {
25+
throw new Error(`Unsafe import path: ${request}`);
26+
}
27+
const resolved = path.resolve(packageRoot, prefix, suffix);
28+
const normalizedRoot = path.resolve(packageRoot) + path.sep;
29+
if (!resolved.startsWith(normalizedRoot)) {
30+
throw new Error(`Import escapes package root: ${request}`);
31+
}
2532
return resolveWithExtensions(resolved);
2633
}
2734
}

0 commit comments

Comments
 (0)