Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -2,11 +2,9 @@
|
||||
/**
|
||||
* Secret-scanning CI gate.
|
||||
*
|
||||
* Walks `apps/`, `packages/`, `scripts/`, `prisma/`, `docs/` (recursively) and
|
||||
* the repository root (top-level files only) looking for hardcoded secrets:
|
||||
* GitHub PATs, GitLab PATs, AWS access keys, payment processor live keys, Slack tokens,
|
||||
* private-key PEM headers, JWT-shaped tokens, and high-entropy assignment
|
||||
* literals on lines that look like secret declarations.
|
||||
* Scans every Git-tracked text file looking for hardcoded secrets: source-host
|
||||
* tokens, cloud/API credentials, private keys, JWT-shaped tokens, embedded URL
|
||||
* credentials, and high-entropy assignment literals on secret-like names.
|
||||
*
|
||||
* Findings on `.env.example` variants or test/fixture/mock/stub paths are
|
||||
* recorded as "reviewed" rather than failures. Lines that contain obvious
|
||||
@@ -17,10 +15,9 @@
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import url from "node:url";
|
||||
|
||||
const RECURSIVE_ROOTS = ["apps", "packages", "scripts", "prisma", "docs"];
|
||||
|
||||
export const SKIP_DIR_NAMES = new Set([
|
||||
"node_modules",
|
||||
"dist",
|
||||
@@ -44,6 +41,15 @@ const SKIP_FILE_SUFFIXES = [
|
||||
".ico",
|
||||
".webp",
|
||||
".pdf",
|
||||
".woff",
|
||||
".woff2",
|
||||
".ttf",
|
||||
".eot",
|
||||
".zip",
|
||||
".gz",
|
||||
".br",
|
||||
".wasm",
|
||||
".mp4",
|
||||
];
|
||||
|
||||
const SKIP_FILE_NAMES = new Set(["pnpm-lock.yaml"]);
|
||||
@@ -56,9 +62,18 @@ const ALLOWLISTED_FILENAMES = new Set([
|
||||
".env.test",
|
||||
]);
|
||||
|
||||
// Path segments (case-insensitive substring) that mark a file as a
|
||||
// test/fixture/mock surface; findings inside are reviewed, not failures.
|
||||
const ALLOWLISTED_PATH_SEGMENTS = ["test", "spec", "fixture", "mock", "stub"];
|
||||
// Exact path components that mark an intentionally synthetic test surface.
|
||||
const ALLOWLISTED_PATH_COMPONENTS = new Set([
|
||||
"test",
|
||||
"tests",
|
||||
"__tests__",
|
||||
"fixture",
|
||||
"fixtures",
|
||||
"mock",
|
||||
"mocks",
|
||||
"stub",
|
||||
"stubs",
|
||||
]);
|
||||
|
||||
// Self-reference: this scanner file describes the patterns it scans for, so
|
||||
// matches against its own source must be treated as reviewed.
|
||||
@@ -97,9 +112,13 @@ export function lineHasPlaceholder(line) {
|
||||
}
|
||||
|
||||
export const PATTERNS = [
|
||||
{ id: "github-pat", regex: /\bghp_[A-Za-z0-9_]{20,}\b/g },
|
||||
{ id: "github-pat", regex: /\bgh[opurs]_[A-Za-z0-9_]{20,}\b/g },
|
||||
{ id: "github-fine-grained-pat", regex: /\bgithub_pat_[A-Za-z0-9_]{20,}\b/g },
|
||||
{ id: "gitlab-pat", regex: /\bglpat-[A-Za-z0-9_-]{20,}\b/g },
|
||||
{ id: "npm-access-token", regex: /\bnpm_[A-Za-z0-9]{30,}\b/g },
|
||||
{ id: "pypi-access-token", regex: /\bpypi-[A-Za-z0-9_-]{40,}\b/g },
|
||||
{ id: "huggingface-token", regex: /\bhf_[A-Za-z0-9]{30,}\b/g },
|
||||
{ id: "google-api-key", regex: /\bAIza[0-9A-Za-z_-]{35}\b/g },
|
||||
{ id: "aws-access-key-id", regex: /\bAKIA[0-9A-Z]{16}\b/g },
|
||||
{ id: "payment-secret-live", regex: /\bsk_live_[A-Za-z0-9]{20,}\b/g },
|
||||
{
|
||||
@@ -112,6 +131,7 @@ export const PATTERNS = [
|
||||
id: "private-key-header",
|
||||
regex: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY-----/g,
|
||||
},
|
||||
{ id: "age-secret-key", regex: /\bAGE-SECRET-KEY-1[0-9A-Z]{20,}\b/g },
|
||||
{
|
||||
id: "jwt-like",
|
||||
regex:
|
||||
@@ -120,7 +140,11 @@ export const PATTERNS = [
|
||||
{
|
||||
id: "generic-high-entropy-assignment",
|
||||
regex:
|
||||
/\b(?:password|secret|token|api_?key|webhook_secret)\s*[:=]\s*['"][A-Za-z0-9+/=_-]{32,}['"]/gi,
|
||||
/\b(?:password|passphrase|secret|token|auth_?token|api_?key|access_?key|client_?secret|private_?key|signing_?key|webhook_?secret)\s*[:=]\s*(?:['"][A-Za-z0-9+/=_-]{24,}['"]|(?=[A-Za-z0-9+/=_-]{32,}\b)(?=[A-Za-z0-9+/=_-]*\d)[A-Za-z0-9+/=_-]{32,})/gi,
|
||||
},
|
||||
{
|
||||
id: "embedded-url-credentials",
|
||||
regex: /\b(?:https?|postgres(?:ql)?|redis):\/\/[^\s/:@]+:[^\s/@]{8,}@[^\s]+/gi,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -128,11 +152,9 @@ export function isAllowlistedPath(absPath) {
|
||||
const basename = path.basename(absPath);
|
||||
if (SELF_FILENAMES.has(basename)) return true;
|
||||
if (ALLOWLISTED_FILENAMES.has(basename)) return true;
|
||||
const lower = absPath.toLowerCase();
|
||||
for (const seg of ALLOWLISTED_PATH_SEGMENTS) {
|
||||
if (lower.includes(seg)) return true;
|
||||
}
|
||||
return false;
|
||||
const components = path.normalize(absPath).toLowerCase().split(path.sep);
|
||||
if (components.some((component) => ALLOWLISTED_PATH_COMPONENTS.has(component))) return true;
|
||||
return /\.(?:test|spec)\.[^.]+$/i.test(basename);
|
||||
}
|
||||
|
||||
export function scanText(text, { filename = "" } = {}) {
|
||||
@@ -150,6 +172,14 @@ export function scanText(text, { filename = "" } = {}) {
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const trailingText = line.slice((match.index ?? 0) + match[0].length);
|
||||
if (
|
||||
pattern.id === "generic-high-entropy-assignment" &&
|
||||
/:\s*[A-Z][A-Z0-9_]*$/.test(match[0]) &&
|
||||
/^\s*[,;)]/.test(trailingText)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
findings.push({
|
||||
file: filename,
|
||||
line: i + 1,
|
||||
@@ -198,36 +228,47 @@ function listFilesRecursive(dir) {
|
||||
return out;
|
||||
}
|
||||
|
||||
function listRootTopLevelFiles(root) {
|
||||
if (!fs.existsSync(root)) return [];
|
||||
const out = [];
|
||||
let entries;
|
||||
try {
|
||||
entries = fs.readdirSync(root, { withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (!entry.isFile()) continue;
|
||||
const abs = path.join(root, entry.name);
|
||||
if (shouldSkipFile(abs)) continue;
|
||||
out.push(abs);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function collectFiles(root) {
|
||||
const files = [];
|
||||
for (const sub of RECURSIVE_ROOTS) {
|
||||
files.push(...listFilesRecursive(path.join(root, sub)));
|
||||
const tracked = spawnSync("git", ["-C", root, "ls-files", "-z"], {
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
});
|
||||
if (tracked.status === 0) {
|
||||
return tracked.stdout
|
||||
.split("\0")
|
||||
.filter(Boolean)
|
||||
.map((relativePath) => path.join(root, relativePath))
|
||||
.filter((absolutePath) => {
|
||||
if (shouldSkipFile(absolutePath)) return false;
|
||||
try {
|
||||
return fs.lstatSync(absolutePath).isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
files.push(...listRootTopLevelFiles(root));
|
||||
return files;
|
||||
return listFilesRecursive(root);
|
||||
}
|
||||
|
||||
function truncate(value, max = 80) {
|
||||
if (value.length <= max) return value;
|
||||
return `${value.slice(0, max)}...`;
|
||||
export function isKnownLocalCredential(finding) {
|
||||
if (finding.patternId !== "embedded-url-credentials") return false;
|
||||
const rawUrl = finding.match
|
||||
.split('"')[0]
|
||||
.split("'")[0]
|
||||
.replace(/^postgres:\/\//, "postgresql://");
|
||||
try {
|
||||
const parsed = new URL(rawUrl);
|
||||
return (
|
||||
parsed.protocol === "postgresql:" &&
|
||||
["localhost", "127.0.0.1", "::1"].includes(parsed.hostname) &&
|
||||
[["postgres", "postgres"], ["hivegrid", "hivegrid"]].some(
|
||||
([username, password]) =>
|
||||
parsed.username === username && parsed.password === password,
|
||||
)
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function evaluate(root = process.cwd()) {
|
||||
@@ -245,7 +286,7 @@ export function evaluate(root = process.cwd()) {
|
||||
if (findings.length === 0) continue;
|
||||
const allowlisted = isAllowlistedPath(file);
|
||||
for (const finding of findings) {
|
||||
if (allowlisted) {
|
||||
if (allowlisted || isKnownLocalCredential(finding)) {
|
||||
reviewed.push(finding);
|
||||
} else {
|
||||
real.push(finding);
|
||||
@@ -260,9 +301,9 @@ export function evaluate(root = process.cwd()) {
|
||||
};
|
||||
}
|
||||
|
||||
function formatFinding(finding, rootRel) {
|
||||
export function formatFinding(finding, rootRel) {
|
||||
const rel = path.relative(rootRel, finding.file) || finding.file;
|
||||
return `${rel}:${finding.line}: ${finding.patternId} matched: ${truncate(finding.match)}`;
|
||||
return `${rel}:${finding.line}: ${finding.patternId} matched [redacted length=${finding.match.length}]`;
|
||||
}
|
||||
|
||||
const isMain =
|
||||
|
||||
Reference in new issue
Block a user