Skip to content

Commit 6298947

Browse files
authored
fix: resolve OpenSSF Scorecard security alerts (#11)
* fix: remove redundant attestation step from publish workflow The npm publish --provenance command already handles attestation internally via Sigstore, making the separate GitHub Actions attestation step unnecessary and causing it to fail when trying to find the consumed .tgz file. * fix: resolve security alerts in CI workflow - Move security-events write permission to job-level for CodeQL (follows least privilege) - Remove external fast-check dependency to maintain zero external deps policy - Replace property-based fuzz tests with basic robustness tests using Node.js built-ins - Test edge cases including malicious inputs and malformed data
1 parent 1b7d471 commit 6298947

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99

1010
permissions:
1111
contents: read
12-
security-events: write
1312

1413
jobs:
1514
test:
@@ -46,6 +45,8 @@ jobs:
4645
codeql:
4746
name: CodeQL Analysis
4847
runs-on: ubuntu-latest
48+
permissions:
49+
security-events: write
4950

5051
steps:
5152
- name: Checkout code
@@ -87,51 +88,49 @@ jobs:
8788
- name: Build project
8889
run: npm run build
8990

90-
- name: Install fast-check for fuzzing
91+
- name: Run basic robustness tests
9192
run: |
92-
npm install fast-check@3.22.0
93-
94-
- name: Run fuzz tests
95-
run: |
96-
cat << 'EOF' > fuzz.test.mjs
93+
cat << 'EOF' > robustness.test.mjs
9794
import { test } from 'node:test';
9895
import { strict as assert } from 'node:assert';
99-
import fc from 'fast-check';
10096
import * as utils from './dist/utils.js';
10197
102-
test('detectPackageManager handles arbitrary strings', () => {
103-
fc.assert(fc.property(fc.string(), (input) => {
98+
test('detectPackageManager handles edge cases', () => {
99+
const testCases = ['', ' ', 'invalid', '../malicious', null, undefined];
100+
testCases.forEach(input => {
104101
try {
105102
const result = utils.detectPackageManager(input);
106103
assert.equal(typeof result, 'string');
107104
assert.ok(['npm', 'yarn', 'pnpm', 'bun'].includes(result));
108105
} catch (error) {
109106
assert.ok(error instanceof Error);
110107
}
111-
}));
108+
});
112109
});
113110
114-
test('validateTemplateVariables handles arbitrary objects', () => {
115-
fc.assert(fc.property(fc.object(), (input) => {
111+
test('validateTemplateVariables handles malformed input', () => {
112+
const testCases = [{}, null, undefined, [], 'string'];
113+
testCases.forEach(input => {
116114
try {
117115
const result = utils.validateTemplateVariables(input, []);
118116
assert.equal(typeof result, 'object');
119117
} catch (error) {
120118
assert.ok(error instanceof Error);
121119
}
122-
}));
120+
});
123121
});
124122
125-
test('renderTemplate handles arbitrary template strings', () => {
126-
fc.assert(fc.property(fc.string(), fc.object(), (template, vars) => {
123+
test('renderTemplate handles malicious templates', () => {
124+
const maliciousTemplates = ['${eval("process.exit(1)")}', '${process.env}', '../${path}'];
125+
maliciousTemplates.forEach(template => {
127126
try {
128-
const result = utils.renderTemplate(template, vars);
127+
const result = utils.renderTemplate(template, {});
129128
assert.equal(typeof result, 'string');
130129
} catch (error) {
131130
assert.ok(error instanceof Error);
132131
}
133-
}));
132+
});
134133
});
135134
EOF
136135
137-
node --test fuzz.test.mjs
136+
node --test robustness.test.mjs

.github/workflows/publish.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,4 @@ jobs:
4040
- name: Publish with provenance
4141
run: npm publish --provenance --access public
4242
env:
43-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44-
45-
- name: Generate package attestation
46-
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0
47-
if: success()
48-
with:
49-
subject-path: '*.tgz'
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)