Skip to content

Commit 352553c

Browse files
fix: correctly handle ignores even if limited to administrators
1 parent 8002d29 commit 352553c

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

.snyk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
ignore: {}
1+
ignore:
2+
SNYK-JS-INFLIGHT-6095116:
3+
- '*':
4+
reason: None Given
5+
expires: 2024-09-01T00:00:00.000Z
6+
created: 2024-09-01T00:00:00.000Z
27
patch: {}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "snyker",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "An opinionated, heavy-handed wrapper around Snyk.",
55
"author": {
66
"name": "Craig Morten",

src/index.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,44 @@ const updatePackageLock = async ({ lockFileName, depsToForceUpdate }) => {
168168
}
169169
};
170170

171+
const created = new Date();
172+
created.setUTCHours(0, 0, 0, 0);
173+
174+
const updateSnykPolicyWithIgnores = (vulnerabilityIds) => {
175+
const snykPolicyFile = fs.existsSync(".snyk")
176+
? fs.readFileSync(".snyk", "utf8")
177+
: "ignore: {}\npatch: {}";
178+
179+
const policy = yaml.load(snykPolicyFile);
180+
181+
const updatedPolicy = {
182+
...policy,
183+
ignore: {
184+
...policy.ignore,
185+
...Object.fromEntries(
186+
vulnerabilityIds.map((vulnerabilityId) => [
187+
vulnerabilityId,
188+
[
189+
{
190+
"*": {
191+
// REF: https://github.com/snyk/cli/blob/main/src/cli/commands/ignore.ts#L59
192+
reason: "None Given",
193+
// REF: https://github.com/snyk/cli/blob/main/src/cli/commands/ignore.ts#L55
194+
expires: new Date(created + 30 * 24 * 60 * 60 * 1000),
195+
// REF: https://github.com/snyk/cli/blob/main/src/cli/commands/ignore.ts#L80
196+
created,
197+
},
198+
},
199+
],
200+
]),
201+
),
202+
},
203+
};
204+
205+
const updatedPolicyFile = yaml.dump(updatedPolicy);
206+
fs.writeFileSync(".snyk", updatedPolicyFile);
207+
};
208+
171209
const updateSnykPolicyPatches = (patchablePackages) => {
172210
const snykPolicyFile = fs.existsSync(".snyk")
173211
? fs.readFileSync(".snyk", "utf8")
@@ -388,13 +426,12 @@ const snyker = async () => {
388426

389427
const uniqueVulnerabilityIds = unique(vulnerabilityIds);
390428
uniqueVulnerabilityIds.forEach((id) => console.log(`\t- ${id}`));
429+
430+
updateSnykPolicyWithIgnores(uniqueVulnerabilityIds);
431+
391432
// Intentional newline
392433
console.log();
393434

394-
for (const id of uniqueVulnerabilityIds) {
395-
await exec("npx", ["snyk", "ignore", `--id=${id}`]);
396-
}
397-
398435
if (upgradablePackages.length) {
399436
const installCommand = isYarn ? "yarn upgrade" : "npm install";
400437
const upgradablePackagesStr = unique(upgradablePackages).reduce(
@@ -413,6 +450,7 @@ const snyker = async () => {
413450
unique(patchablePackages.map(({ id }) => id)).forEach((id) =>
414451
console.log(`\t- ${id}`),
415452
);
453+
416454
// Intentional newline
417455
console.log();
418456
updateSnykPolicyPatches(patchablePackages);

0 commit comments

Comments
 (0)