reposec 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +733 -0
- package/SECURITY.md +29 -0
- package/bin/reposec.mjs +20 -0
- package/lib/baseline.ts +100 -0
- package/lib/client-bundle.ts +202 -0
- package/lib/exporters.ts +509 -0
- package/lib/fingerprint.ts +5 -0
- package/lib/github.ts +365 -0
- package/lib/local-repo.ts +182 -0
- package/lib/rules.ts +662 -0
- package/lib/scan-targets.ts +155 -0
- package/lib/scanner.ts +2015 -0
- package/lib/scoring.ts +58 -0
- package/lib/types.ts +133 -0
- package/lib/utils.ts +24 -0
- package/lib/verification.ts +67 -0
- package/package.json +66 -0
- package/scripts/reposec-cli.mts +195 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export const SECRET_SCAN_MAX_FILE_BYTES = 1_500_000;
|
|
2
|
+
|
|
3
|
+
export const SECRET_SCAN_SKIP_FILES = new Set([
|
|
4
|
+
"package-lock.json",
|
|
5
|
+
"yarn.lock",
|
|
6
|
+
"pnpm-lock.yaml",
|
|
7
|
+
"bun.lockb",
|
|
8
|
+
"composer.lock",
|
|
9
|
+
"Gemfile.lock",
|
|
10
|
+
"Cargo.lock",
|
|
11
|
+
"poetry.lock",
|
|
12
|
+
"Pipfile.lock",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"SECURITY.md",
|
|
15
|
+
"README.md",
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"CODEOWNERS",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const SECRET_SCAN_SKIP_PATH_TOKENS = [
|
|
21
|
+
"node_modules/",
|
|
22
|
+
"vendor/",
|
|
23
|
+
"dist/",
|
|
24
|
+
"build/",
|
|
25
|
+
".next/",
|
|
26
|
+
"out/",
|
|
27
|
+
"coverage/",
|
|
28
|
+
"target/",
|
|
29
|
+
"bower_components/",
|
|
30
|
+
"jspm_packages/",
|
|
31
|
+
".gradle/",
|
|
32
|
+
"Pods/",
|
|
33
|
+
".terraform/",
|
|
34
|
+
".venv/",
|
|
35
|
+
"venv/",
|
|
36
|
+
"__pycache__/",
|
|
37
|
+
".git/",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export const SECRET_SCAN_EXTENSIONS = [
|
|
41
|
+
".ts",
|
|
42
|
+
".tsx",
|
|
43
|
+
".js",
|
|
44
|
+
".jsx",
|
|
45
|
+
".mjs",
|
|
46
|
+
".cjs",
|
|
47
|
+
".json",
|
|
48
|
+
".json5",
|
|
49
|
+
".map",
|
|
50
|
+
".yml",
|
|
51
|
+
".yaml",
|
|
52
|
+
".env",
|
|
53
|
+
".py",
|
|
54
|
+
".rb",
|
|
55
|
+
".go",
|
|
56
|
+
".java",
|
|
57
|
+
".kt",
|
|
58
|
+
".swift",
|
|
59
|
+
".php",
|
|
60
|
+
".sh",
|
|
61
|
+
".toml",
|
|
62
|
+
".ini",
|
|
63
|
+
".cfg",
|
|
64
|
+
".conf",
|
|
65
|
+
".config",
|
|
66
|
+
".pem",
|
|
67
|
+
".key",
|
|
68
|
+
".crt",
|
|
69
|
+
".npmrc",
|
|
70
|
+
".pypirc",
|
|
71
|
+
".netrc",
|
|
72
|
+
".tf",
|
|
73
|
+
".tfvars",
|
|
74
|
+
".hcl",
|
|
75
|
+
".bash",
|
|
76
|
+
".zsh",
|
|
77
|
+
".fish",
|
|
78
|
+
".ps1",
|
|
79
|
+
".dart",
|
|
80
|
+
".lua",
|
|
81
|
+
".rs",
|
|
82
|
+
".scala",
|
|
83
|
+
".clj",
|
|
84
|
+
".ex",
|
|
85
|
+
".exs",
|
|
86
|
+
".xml",
|
|
87
|
+
".properties",
|
|
88
|
+
".htaccess",
|
|
89
|
+
".sql",
|
|
90
|
+
".graphql",
|
|
91
|
+
".gql",
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
export const SECRET_SCAN_FILENAMES = new Set([
|
|
95
|
+
".env",
|
|
96
|
+
".env.local",
|
|
97
|
+
".env.development",
|
|
98
|
+
".env.production",
|
|
99
|
+
".env.test",
|
|
100
|
+
".npmrc",
|
|
101
|
+
".pypirc",
|
|
102
|
+
".netrc",
|
|
103
|
+
".htpasswd",
|
|
104
|
+
"id_rsa",
|
|
105
|
+
"id_dsa",
|
|
106
|
+
"id_ecdsa",
|
|
107
|
+
"id_ed25519",
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
export function isLikelySecretScanPath(path: string, size?: number): boolean {
|
|
111
|
+
if (typeof size === "number" && size > SECRET_SCAN_MAX_FILE_BYTES) return false;
|
|
112
|
+
|
|
113
|
+
const normalized = path.replace(/\\/g, "/");
|
|
114
|
+
const lower = normalized.toLowerCase();
|
|
115
|
+
const base = normalized.split("/").pop() ?? normalized;
|
|
116
|
+
|
|
117
|
+
if (SECRET_SCAN_SKIP_FILES.has(normalized) || SECRET_SCAN_SKIP_FILES.has(base)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
for (const token of SECRET_SCAN_SKIP_PATH_TOKENS) {
|
|
121
|
+
if (lower.includes(token.toLowerCase())) return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (lower.includes("/test/") || lower.includes("/tests/")) return false;
|
|
125
|
+
if (lower.includes("__tests__/") || lower.includes("__mocks__/")) return false;
|
|
126
|
+
if (lower.includes("__snapshots__/") || lower.includes("__fixtures__/")) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (lower.includes("fixtures/") || lower.includes("snapshots/")) return false;
|
|
130
|
+
|
|
131
|
+
const isEnvLike = base.startsWith(".env") || SECRET_SCAN_FILENAMES.has(base);
|
|
132
|
+
const hasKnownExt = SECRET_SCAN_EXTENSIONS.some((ext) => lower.endsWith(ext));
|
|
133
|
+
return isEnvLike || hasKnownExt;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function secretScanPriority(path: string): number {
|
|
137
|
+
const lower = path.toLowerCase();
|
|
138
|
+
const base = path.replace(/\\/g, "/").split("/").pop() ?? path;
|
|
139
|
+
if (base === ".env" || base === ".env.local") return 100;
|
|
140
|
+
if (base.startsWith(".env")) return 90;
|
|
141
|
+
if (SECRET_SCAN_FILENAMES.has(base)) return 80;
|
|
142
|
+
if (lower.endsWith(".json") || lower.endsWith(".yml") || lower.endsWith(".yaml")) {
|
|
143
|
+
return 40;
|
|
144
|
+
}
|
|
145
|
+
if (
|
|
146
|
+
lower.endsWith(".ts") ||
|
|
147
|
+
lower.endsWith(".tsx") ||
|
|
148
|
+
lower.endsWith(".js") ||
|
|
149
|
+
lower.endsWith(".jsx") ||
|
|
150
|
+
lower.endsWith(".py")
|
|
151
|
+
) {
|
|
152
|
+
return 30;
|
|
153
|
+
}
|
|
154
|
+
return 20;
|
|
155
|
+
}
|