Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-kids-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/tarball": minor
---

(Tarball) detect and flag with hasExternalCapacity when native fetch is used
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion workspaces/tarball/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@nodesecure/conformance": "^1.0.0",
"@nodesecure/fs-walk": "^2.0.0",
"@nodesecure/js-x-ray": "^8.1.0",
"@nodesecure/js-x-ray": "^8.2.0",
"@nodesecure/mama": "^1.1.0",
"@nodesecure/npm-types": "^1.2.0",
"@nodesecure/utils": "^2.1.0",
Expand Down
13 changes: 11 additions & 2 deletions workspaces/tarball/src/sast/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export interface scanFileReport {
tryDependencies: string[];
dependencies: string[];
filesDependencies: string[];
filesFlags: {
hasExternalCapacity: boolean;
};
}

export async function scanFile(
Expand Down Expand Up @@ -53,7 +56,10 @@ export async function scanFile(
isMinified: result.isMinified,
tryDependencies,
dependencies: packages,
filesDependencies: files
filesDependencies: files,
filesFlags: {
hasExternalCapacity: result.flags.has("fetch")
}
};
}

Expand All @@ -63,7 +69,10 @@ export async function scanFile(
isMinified: false,
tryDependencies: [],
dependencies: [],
filesDependencies: []
filesDependencies: [],
filesFlags: {
hasExternalCapacity: false
}
};
}

Expand Down
2 changes: 2 additions & 0 deletions workspaces/tarball/src/tarball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export async function scanDirOrArchive(
const filesDependencies = [...new Set(scannedFiles.flatMap((row) => row.filesDependencies))];
const tryDependencies = new Set(scannedFiles.flatMap((row) => row.tryDependencies));
const minifiedFiles = scannedFiles.filter((row) => row.isMinified).flatMap((row) => row.file);
const hasExternalCapacity = scannedFiles.some((row) => row.filesFlags.hasExternalCapacity);

const {
nodeDependencies,
Expand All @@ -156,6 +157,7 @@ export async function scanDirOrArchive(

ref.flags.push(...booleanToFlags({
...flags,
hasExternalCapacity: hasExternalCapacity || flags.hasExternalCapacity,
hasNoLicense: spdx.uniqueLicenseIds.length === 0,
hasMultipleLicenses: spdx.uniqueLicenseIds.length > 1,
hasMinifiedCode: minifiedFiles.length > 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const apiService = async (url) => fetch(url);

export default apiService;
35 changes: 31 additions & 4 deletions workspaces/tarball/test/sast/scanFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ test("scanFile (fixture one.js)", async() => {
isMinified: false,
tryDependencies: [],
dependencies: ["http", "mocha"],
filesDependencies: ["src\\foo.js", "home\\marco.js"].map((location) => location.replaceAll("\\", path.sep))
filesDependencies: ["src\\foo.js", "home\\marco.js"].map((location) => location.replaceAll("\\", path.sep)),
filesFlags: {
hasExternalCapacity: false
}
});
});

Expand All @@ -31,7 +34,10 @@ test("scanFile (fixture two.min.js)", async() => {
isMinified: true,
tryDependencies: ["http"],
dependencies: ["http", "fs"],
filesDependencies: []
filesDependencies: [],
filesFlags: {
hasExternalCapacity: false
}
});
});

Expand All @@ -43,7 +49,10 @@ test("scanFile (fixture onelineStmt.min.js)", async() => {
isMinified: false,
tryDependencies: [],
dependencies: [],
filesDependencies: ["foobar.js"]
filesDependencies: ["foobar.js"],
filesFlags: {
hasExternalCapacity: false
}
});
});

Expand All @@ -63,6 +72,24 @@ test("scanFile (fixture parsingError.js)", async() => {
isMinified: false,
tryDependencies: [],
dependencies: [],
filesDependencies: []
filesDependencies: [],
filesFlags: {
hasExternalCapacity: false
}
});
});

test("scanFile (fixture fetch.js)", async() => {
const result = await scanFile(kFixturePath, "fetch.js", "yolo");
assert.deepEqual(result, {
file: "fetch.js",
warnings: [],
isMinified: false,
tryDependencies: [],
dependencies: [],
filesDependencies: [],
filesFlags: {
hasExternalCapacity: true
}
});
});