Skip to content

Commit 74b821b

Browse files
committed
lint
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
1 parent d38d787 commit 74b821b

23 files changed

Lines changed: 3710 additions & 2544 deletions

index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export {
99
commandsExecuted,
1010
safeExistsSync,
1111
safeMkdirSync,
12-
safeReadFileSync,
1312
safeReaddirSync,
13+
safeReadFileSync,
1414
safeSpawnSync,
1515
} from "./src/common/safe.js";
1616
export {
@@ -64,7 +64,9 @@ export const SUPPORTED_TARGETS = Object.freeze([
6464
*/
6565
export function getCommandPlan(options = {}) {
6666
const platform = normalizePlatform(options.platform ?? process.platform);
67-
const architecture = normalizeArchitecture(options.architecture ?? process.arch);
67+
const architecture = normalizeArchitecture(
68+
options.architecture ?? process.arch,
69+
);
6870

6971
if (platform === "darwin" && architecture === "arm64") {
7072
return getDarwinArm64CommandPlan();
@@ -99,7 +101,9 @@ export function getCommandPlan(options = {}) {
99101
*/
100102
export async function collectHardware(options = {}) {
101103
const platform = normalizePlatform(options.platform ?? process.platform);
102-
const architecture = normalizeArchitecture(options.architecture ?? process.arch);
104+
const architecture = normalizeArchitecture(
105+
options.architecture ?? process.arch,
106+
);
103107

104108
if (platform === "darwin" && architecture === "arm64") {
105109
return collectDarwinArm64Hardware(options);
@@ -176,7 +180,9 @@ export async function collectHardware(options = {}) {
176180
*/
177181
export function buildHardwareFromSources(options) {
178182
const platform = normalizePlatform(options?.platform ?? process.platform);
179-
const architecture = normalizeArchitecture(options?.architecture ?? process.arch);
183+
const architecture = normalizeArchitecture(
184+
options?.architecture ?? process.arch,
185+
);
180186

181187
if (platform === "darwin" && architecture === "arm64") {
182188
return buildDarwinArm64Hbom(options);

jsr.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
"version": "0.1.0",
44
"license": "MIT",
55
"exports": "./index.js",
6-
"include": [
7-
"index.js",
8-
"src/",
9-
"README.md"
10-
],
6+
"include": ["index.js", "src/", "README.md"],
117
"exclude": [
128
".github/",
139
"bin/",
@@ -17,4 +13,4 @@
1713
"*-hbom*.json",
1814
"*.tgz"
1915
]
20-
}
16+
}

src/common/safe.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
2-
import { basename, resolve } from "node:path";
31
import { spawnSync } from "node:child_process";
2+
import { existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
3+
import { basename, resolve } from "node:path";
44
import process from "node:process";
55

66
/**
@@ -143,20 +143,33 @@ export function safeSpawnSync(command, args = [], options = {}) {
143143
const allowedCommands = normalizeAllowedCommands(options.allowedCommands);
144144
const commandName = basename(command);
145145

146-
if (allowedCommands && !allowedCommands.has(command) && !allowedCommands.has(commandName)) {
146+
if (
147+
allowedCommands &&
148+
!allowedCommands.has(command) &&
149+
!allowedCommands.has(commandName)
150+
) {
147151
return {
148152
status: 1,
149153
stdout: options.encoding === "buffer" ? Buffer.alloc(0) : "",
150-
stderr: options.encoding === "buffer" ? Buffer.from("Command blocked by allowlist") : "Command blocked by allowlist",
154+
stderr:
155+
options.encoding === "buffer"
156+
? Buffer.from("Command blocked by allowlist")
157+
: "Command blocked by allowlist",
151158
error: new Error(`Command blocked by allowlist: ${command}`),
152159
};
153160
}
154161

155-
if (options.shell === true && isWindowsShellHijackRisk(command, options.cwd)) {
162+
if (
163+
options.shell === true &&
164+
isWindowsShellHijackRisk(command, options.cwd)
165+
) {
156166
return {
157167
status: 1,
158168
stdout: options.encoding === "buffer" ? Buffer.alloc(0) : "",
159-
stderr: options.encoding === "buffer" ? Buffer.from("Blocked potential Windows shell hijack") : "Blocked potential Windows shell hijack",
169+
stderr:
170+
options.encoding === "buffer"
171+
? Buffer.from("Blocked potential Windows shell hijack")
172+
: "Blocked potential Windows shell hijack",
160173
error: new Error("Blocked potential Windows shell hijack"),
161174
};
162175
}
@@ -184,11 +197,14 @@ export function safeSpawnSync(command, args = [], options = {}) {
184197
*/
185198
function normalizeAllowedCommands(allowedCommands) {
186199
if (Array.isArray(allowedCommands) && allowedCommands.length > 0) {
187-
return new Set(allowedCommands.map((entry) => entry.trim()).filter(Boolean));
200+
return new Set(
201+
allowedCommands.map((entry) => entry.trim()).filter(Boolean),
202+
);
188203
}
189204

190205
const envValue =
191-
process.env.CDX_HBOM_ALLOWED_COMMANDS ?? process.env.CDXGEN_ALLOWED_COMMANDS;
206+
process.env.CDX_HBOM_ALLOWED_COMMANDS ??
207+
process.env.CDXGEN_ALLOWED_COMMANDS;
192208

193209
if (!envValue) {
194210
return null;
@@ -220,7 +236,12 @@ function isWindowsShellHijackRisk(command, cwd) {
220236
.filter(Boolean)
221237
.map((extension) => extension.toLowerCase());
222238
const cwdPath = resolve(cwd);
223-
const candidates = [candidateBase, ...pathExt.map((extension) => `${candidateBase}${extension}`)];
239+
const candidates = [
240+
candidateBase,
241+
...pathExt.map((extension) => `${candidateBase}${extension}`),
242+
];
224243

225-
return candidates.some((candidate) => safeExistsSync(resolve(cwdPath, candidate)));
244+
return candidates.some((candidate) =>
245+
safeExistsSync(resolve(cwdPath, candidate)),
246+
);
226247
}

src/common/schema.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { randomUUID } from "node:crypto";
22

33
export const HBOM_BOM_FORMAT = "CycloneDX";
44
export const HBOM_SPEC_VERSION = "1.7";
5-
export const HBOM_SCHEMA_URL = "http://cyclonedx.org/schema/bom-1.7.schema.json";
5+
export const HBOM_SCHEMA_URL =
6+
"http://cyclonedx.org/schema/bom-1.7.schema.json";
67

78
/**
89
* Create a CycloneDX 1.7 BOM envelope for hardware inventory.

src/darwin/arm64/commands.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ export const DARWIN_ARM64_COMMANDS = Object.freeze([
118118
purpose:
119119
"Planned enrichment for low-level Apple platform model and registry-backed identifiers via plist output.",
120120
phase: "planned-enrichment",
121-
sensitiveFields: ["IOPlatformSerialNumber", "IOPlatformUUID", "serial-number"],
121+
sensitiveFields: [
122+
"IOPlatformSerialNumber",
123+
"IOPlatformUUID",
124+
"serial-number",
125+
],
122126
}),
123127
Object.freeze({
124128
id: "storage-plist",
@@ -158,7 +162,8 @@ export const DARWIN_ARM64_COMMANDS = Object.freeze([
158162
command: "/usr/bin/sw_vers",
159163
args: [],
160164
parser: "sw-vers-text",
161-
purpose: "Planned metadata enrichment for Darwin version and build context.",
165+
purpose:
166+
"Planned metadata enrichment for Darwin version and build context.",
162167
phase: "planned-enrichment",
163168
}),
164169
]);

0 commit comments

Comments
 (0)