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/little-suns-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/scanner": minor
---

Implement a new Probe extractor for flags
3 changes: 3 additions & 0 deletions workspaces/scanner/docs/extractors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Available probes include:
| ContactExtractor | manifest |
| LicensesExtractor | manifest |
| SizeExtractor | manifest |
| FlagsExtractor | manifest |
| VulnerabilitiesExtractor | packument |
| WarningsExtractor | manifest |

All probes follow the same `ProbeExtractor` interface, which acts as an iterator-like contract:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Import Third-party Dependencies
import FrequencySet from "frequency-set";

// Import Internal Dependencies
import type {
ManifestProbeExtractor
} from "../payload.js";
import type { DependencyVersion } from "../../types.js";

export type FlagsExtractorResult = {
flags: Record<string, number>;
};

export class FlagsExtractor implements ManifestProbeExtractor<FlagsExtractorResult> {
level = "manifest" as const;

#flags = new FrequencySet();

next(
_: string,
version: DependencyVersion
) {
const { flags } = version;

flags.forEach((flagName) => this.#flags.add(flagName));
}

done() {
return {
flags: Object.fromEntries(this.#flags)
};
}
}
1 change: 1 addition & 0 deletions workspaces/scanner/src/extractors/probes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./LicensesExtractor.class.js";
export * from "./ContactExtractor.class.js";
export * from "./WarningsExtractor.class.js";
export * from "./VulnerabilitiesExtractor.class.js";
export * from "./FlagsExtractor.class.js";
24 changes: 24 additions & 0 deletions workspaces/scanner/test/extractors/payload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ describe("Extractors.Probes", () => {
});
});

describe("FlagsExtractor", () => {
it("should extract strnum flags", () => {
const extractor = new Extractors.Payload(
strnumNodesecurePayload,
[
new Extractors.Probes.FlagsExtractor()
]
);

const {
flags
} = extractor.extractAndMerge();

assert.deepEqual(
flags,
{
hasWarnings: 1,
isOutdated: 1,
hasManyPublishers: 1
}
Comment thread
fraxken marked this conversation as resolved.
);
});
});

describe("VulnerabilitiesExtractor", () => {
it("should extract strnum warnings", () => {
const fakePayload: any = {
Expand Down