@next-secure-check/core 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 +13 -0
- package/dist/file-collector.d.ts +8 -0
- package/dist/file-collector.d.ts.map +1 -0
- package/dist/file-collector.js +122 -0
- package/dist/file-collector.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/project-detector.d.ts +3 -0
- package/dist/project-detector.d.ts.map +1 -0
- package/dist/project-detector.js +74 -0
- package/dist/project-detector.js.map +1 -0
- package/dist/scanner.d.ts +4 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +62 -0
- package/dist/scanner.js.map +1 -0
- package/dist/score.d.ts +4 -0
- package/dist/score.d.ts.map +1 -0
- package/dist/score.js +47 -0
- package/dist/score.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SetraTheXX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @next-secure-check/core
|
|
2
|
+
|
|
3
|
+
Core scanner engine and shared TypeScript types for `next-secure-check`.
|
|
4
|
+
|
|
5
|
+
This is an internal workspace package published for the `next-secure-check` CLI. It contains project detection, file collection, scan orchestration, scoring, and public result types. Most users should install the CLI package instead:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx next-secure-check scan .
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
See the main repository for documentation:
|
|
12
|
+
|
|
13
|
+
https://github.com/SetraTheXX/next-secure-check
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SourceFile } from "./types.js";
|
|
2
|
+
type CollectFilesOptions = {
|
|
3
|
+
excludePaths?: string[];
|
|
4
|
+
};
|
|
5
|
+
export declare function collectFiles(rootPath: string, options?: CollectFilesOptions): Promise<SourceFile[]>;
|
|
6
|
+
export declare function normalizePath(filePath: string): string;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=file-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-collector.d.ts","sourceRoot":"","sources":["../src/file-collector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,mBAAmB,GAAG;IACzB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAkCF,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAK7G;AAsDD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const IGNORED_DIRECTORIES = new Set([
|
|
4
|
+
".git",
|
|
5
|
+
".next",
|
|
6
|
+
".turbo",
|
|
7
|
+
".vercel",
|
|
8
|
+
"build",
|
|
9
|
+
"coverage",
|
|
10
|
+
"dist",
|
|
11
|
+
"node_modules"
|
|
12
|
+
]);
|
|
13
|
+
const INCLUDED_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".json"]);
|
|
14
|
+
const INCLUDED_FILENAMES = new Set([
|
|
15
|
+
".env",
|
|
16
|
+
".env.development",
|
|
17
|
+
".env.development.local",
|
|
18
|
+
".env.example",
|
|
19
|
+
".env.local",
|
|
20
|
+
".env.production",
|
|
21
|
+
".env.production.local",
|
|
22
|
+
".env.staging",
|
|
23
|
+
".env.staging.local",
|
|
24
|
+
".env.test",
|
|
25
|
+
".env.test.local",
|
|
26
|
+
"middleware.js",
|
|
27
|
+
"middleware.ts",
|
|
28
|
+
"next.config.js",
|
|
29
|
+
"next.config.mjs",
|
|
30
|
+
"next.config.ts",
|
|
31
|
+
"package.json"
|
|
32
|
+
]);
|
|
33
|
+
export async function collectFiles(rootPath, options = {}) {
|
|
34
|
+
const files = [];
|
|
35
|
+
const excludeMatchers = createExcludeMatchers(options.excludePaths);
|
|
36
|
+
await walk(rootPath, rootPath, files, excludeMatchers);
|
|
37
|
+
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
38
|
+
}
|
|
39
|
+
async function walk(rootPath, currentPath, files, excludeMatchers) {
|
|
40
|
+
const entries = await readdir(currentPath, { withFileTypes: true });
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
if (entry.isDirectory() && IGNORED_DIRECTORIES.has(entry.name)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const absolutePath = path.join(currentPath, entry.name);
|
|
46
|
+
if (entry.isDirectory()) {
|
|
47
|
+
await walk(rootPath, absolutePath, files, excludeMatchers);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!entry.isFile() || !shouldInclude(entry.name)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const relativePath = normalizePath(path.relative(rootPath, absolutePath));
|
|
54
|
+
if (isExcluded(relativePath, excludeMatchers)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const fileStat = await stat(absolutePath);
|
|
58
|
+
if (fileStat.size > 1024 * 1024) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const content = await readFile(absolutePath, "utf8");
|
|
62
|
+
files.push({
|
|
63
|
+
path: relativePath,
|
|
64
|
+
absolutePath,
|
|
65
|
+
content,
|
|
66
|
+
lines: content.split(/\r?\n/)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function shouldInclude(fileName) {
|
|
71
|
+
if (INCLUDED_FILENAMES.has(fileName)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return INCLUDED_EXTENSIONS.has(path.extname(fileName));
|
|
75
|
+
}
|
|
76
|
+
export function normalizePath(filePath) {
|
|
77
|
+
return filePath.split(path.sep).join("/");
|
|
78
|
+
}
|
|
79
|
+
function isExcluded(relativePath, excludeMatchers) {
|
|
80
|
+
return excludeMatchers.some((matcher) => matcher.test(relativePath));
|
|
81
|
+
}
|
|
82
|
+
function createExcludeMatchers(patterns) {
|
|
83
|
+
return (patterns ?? [])
|
|
84
|
+
.map((pattern) => normalizeExcludePattern(pattern))
|
|
85
|
+
.filter((pattern) => pattern.length > 0)
|
|
86
|
+
.map((pattern) => globToRegExp(pattern));
|
|
87
|
+
}
|
|
88
|
+
function normalizeExcludePattern(pattern) {
|
|
89
|
+
return pattern.trim().replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "");
|
|
90
|
+
}
|
|
91
|
+
function globToRegExp(pattern) {
|
|
92
|
+
let source = "^";
|
|
93
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
94
|
+
const char = pattern[index];
|
|
95
|
+
const next = pattern[index + 1];
|
|
96
|
+
const afterNext = pattern[index + 2];
|
|
97
|
+
if (char === "*" && next === "*" && afterNext === "/") {
|
|
98
|
+
source += "(?:.*/)?";
|
|
99
|
+
index += 2;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (char === "*" && next === "*") {
|
|
103
|
+
source += ".*";
|
|
104
|
+
index += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (char === "*") {
|
|
108
|
+
source += "[^/]*";
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (char === "?") {
|
|
112
|
+
source += "[^/]";
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
source += escapeRegExp(char);
|
|
116
|
+
}
|
|
117
|
+
return new RegExp(`${source}$`);
|
|
118
|
+
}
|
|
119
|
+
function escapeRegExp(char) {
|
|
120
|
+
return /[\\^$.*+?()[\]{}|]/.test(char) ? `\\${char}` : char;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=file-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-collector.js","sourceRoot":"","sources":["../src/file-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,MAAM;IACN,OAAO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I,IAAI,KAAK,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YACtD,MAAM,IAAI,UAAU,CAAC;YACrB,KAAK,IAAI,CAAC,CAAC;YACX,SAAS;QACX,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjC,MAAM,IAAI,IAAI,CAAC;YACf,KAAK,IAAI,CAAC,CAAC;YACX,SAAS;QACX,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,OAAO,CAAC;YAClB,SAAS;QACX,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,MAAM,CAAC;YACjB,SAAS;QACX,CAAC;QAED,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { Confidence, Finding, ProjectInfo, RiskLevel, Rule, ScanContext, ScanOptions, ScanResult, ScanSummary, Severity, SourceFile } from "./types.js";
|
|
2
|
+
export { collectFiles, normalizePath } from "./file-collector.js";
|
|
3
|
+
export { detectProject } from "./project-detector.js";
|
|
4
|
+
export { riskLevelForScore, summarizeFindings } from "./score.js";
|
|
5
|
+
export { resolveProjectPath, scanProject } from "./scanner.js";
|
|
6
|
+
export declare function createScanResultSkeleton(targetPath: string, toolVersion?: string): import("./types.js").ScanResult;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,OAAO,EACP,WAAW,EACX,SAAS,EACT,IAAI,EACJ,WAAW,EACX,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/D,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,SAAU,GAAG,OAAO,YAAY,EAAE,UAAU,CA0BnH"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export { collectFiles, normalizePath } from "./file-collector.js";
|
|
2
|
+
export { detectProject } from "./project-detector.js";
|
|
3
|
+
export { riskLevelForScore, summarizeFindings } from "./score.js";
|
|
4
|
+
export { resolveProjectPath, scanProject } from "./scanner.js";
|
|
5
|
+
export function createScanResultSkeleton(targetPath, toolVersion = "0.0.0") {
|
|
6
|
+
const startedAt = Date.now();
|
|
7
|
+
return {
|
|
8
|
+
project: {
|
|
9
|
+
name: targetPath,
|
|
10
|
+
framework: "unknown",
|
|
11
|
+
router: "unknown",
|
|
12
|
+
language: "unknown"
|
|
13
|
+
},
|
|
14
|
+
summary: {
|
|
15
|
+
score: 100,
|
|
16
|
+
riskLevel: "excellent",
|
|
17
|
+
totalFindings: 0,
|
|
18
|
+
high: 0,
|
|
19
|
+
medium: 0,
|
|
20
|
+
low: 0,
|
|
21
|
+
info: 0
|
|
22
|
+
},
|
|
23
|
+
findings: [],
|
|
24
|
+
metadata: {
|
|
25
|
+
scannedAt: new Date(startedAt).toISOString(),
|
|
26
|
+
durationMs: Date.now() - startedAt,
|
|
27
|
+
toolVersion
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/D,MAAM,UAAU,wBAAwB,CAAC,UAAkB,EAAE,WAAW,GAAG,OAAO;IAChF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,OAAO;QACL,OAAO,EAAE;YACP,IAAI,EAAE,UAAU;YAChB,SAAS,EAAE,SAAS;YACpB,MAAM,EAAE,SAAS;YACjB,QAAQ,EAAE,SAAS;SACpB;QACD,OAAO,EAAE;YACP,KAAK,EAAE,GAAG;YACV,SAAS,EAAE,WAAW;YACtB,aAAa,EAAE,CAAC;YAChB,IAAI,EAAE,CAAC;YACP,MAAM,EAAE,CAAC;YACT,GAAG,EAAE,CAAC;YACN,IAAI,EAAE,CAAC;SACR;QACD,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE;YACR,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;YAC5C,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YAClC,WAAW;SACZ;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-detector.d.ts","sourceRoot":"","sources":["../src/project-detector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAcvE,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,GAAG,SAAS,CAAC,CA8BjH"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function detectProject(files, rootPath) {
|
|
3
|
+
const packageJsonFile = files.find((file) => file.path === "package.json");
|
|
4
|
+
const packageJson = parsePackageJson(packageJsonFile?.content);
|
|
5
|
+
const allDependencies = {
|
|
6
|
+
...packageJson.dependencies,
|
|
7
|
+
...packageJson.devDependencies
|
|
8
|
+
};
|
|
9
|
+
const hasNextDependency = "next" in allDependencies;
|
|
10
|
+
const hasReactDependency = "react" in allDependencies || files.some((file) => /\.(tsx|jsx)$/.test(file.path));
|
|
11
|
+
const hasNextStructure = files.some((file) => file.path.startsWith("app/") || file.path.startsWith("src/app/"));
|
|
12
|
+
const hasApiRoutes = files.some((file) => file.path.includes("/api/") || file.path.startsWith("pages/api/"));
|
|
13
|
+
const project = {
|
|
14
|
+
name: packageJson.name ?? path.basename(rootPath),
|
|
15
|
+
framework: hasNextDependency || hasNextStructure || hasApiRoutes ? "nextjs" : hasReactDependency ? "react" : "node",
|
|
16
|
+
router: detectRouter(files),
|
|
17
|
+
language: detectLanguage(files)
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
packageJson: packageJsonFile
|
|
21
|
+
? {
|
|
22
|
+
name: packageJson.name,
|
|
23
|
+
dependencies: packageJson.dependencies,
|
|
24
|
+
devDependencies: packageJson.devDependencies
|
|
25
|
+
}
|
|
26
|
+
: undefined,
|
|
27
|
+
project
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function parsePackageJson(content) {
|
|
31
|
+
if (!content) {
|
|
32
|
+
return { dependencies: {}, devDependencies: {} };
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(content);
|
|
36
|
+
return {
|
|
37
|
+
name: parsed.name,
|
|
38
|
+
dependencies: parsed.dependencies ?? {},
|
|
39
|
+
devDependencies: parsed.devDependencies ?? {}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { dependencies: {}, devDependencies: {} };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function detectRouter(files) {
|
|
47
|
+
const hasApp = files.some((file) => file.path.startsWith("app/") || file.path.startsWith("src/app/"));
|
|
48
|
+
const hasPages = files.some((file) => file.path.startsWith("pages/") || file.path.startsWith("src/pages/"));
|
|
49
|
+
if (hasApp && hasPages) {
|
|
50
|
+
return "mixed";
|
|
51
|
+
}
|
|
52
|
+
if (hasApp) {
|
|
53
|
+
return "app";
|
|
54
|
+
}
|
|
55
|
+
if (hasPages) {
|
|
56
|
+
return "pages";
|
|
57
|
+
}
|
|
58
|
+
return "unknown";
|
|
59
|
+
}
|
|
60
|
+
function detectLanguage(files) {
|
|
61
|
+
const hasTypeScript = files.some((file) => /\.(ts|tsx)$/.test(file.path));
|
|
62
|
+
const hasJavaScript = files.some((file) => /\.(js|jsx)$/.test(file.path));
|
|
63
|
+
if (hasTypeScript && hasJavaScript) {
|
|
64
|
+
return "mixed";
|
|
65
|
+
}
|
|
66
|
+
if (hasTypeScript) {
|
|
67
|
+
return "typescript";
|
|
68
|
+
}
|
|
69
|
+
if (hasJavaScript) {
|
|
70
|
+
return "javascript";
|
|
71
|
+
}
|
|
72
|
+
return "unknown";
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=project-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-detector.js","sourceRoot":"","sources":["../src/project-detector.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAe7B,MAAM,UAAU,aAAa,CAAC,KAAmB,EAAE,QAAgB;IACjE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,CAA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AE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CAAC,KAAmB;IACzC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE1E,IAAI,aAAa,IAAI,aAAa,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ScanOptions, ScanResult } from "./types.js";
|
|
2
|
+
export declare function scanProject(targetPath: string, options?: ScanOptions): Promise<ScanResult>;
|
|
3
|
+
export declare function resolveProjectPath(targetPath: string): Promise<string>;
|
|
4
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA8B,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEtF,wBAAsB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CA4BpG;AAED,wBAAsB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU5E"}
|
package/dist/scanner.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { access, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { collectFiles } from "./file-collector.js";
|
|
4
|
+
import { detectProject } from "./project-detector.js";
|
|
5
|
+
import { summarizeFindings } from "./score.js";
|
|
6
|
+
export async function scanProject(targetPath, options = {}) {
|
|
7
|
+
const startedAt = Date.now();
|
|
8
|
+
const rootPath = await resolveProjectPath(targetPath);
|
|
9
|
+
const files = await collectFiles(rootPath, {
|
|
10
|
+
excludePaths: options.excludePaths
|
|
11
|
+
});
|
|
12
|
+
const detection = detectProject(files, rootPath);
|
|
13
|
+
const categories = normalizeCategories(options.categories);
|
|
14
|
+
const rules = (options.rules ?? []).filter((rule) => categories.size === 0 || categories.has(rule.category));
|
|
15
|
+
const context = {
|
|
16
|
+
targetPath,
|
|
17
|
+
rootPath,
|
|
18
|
+
files,
|
|
19
|
+
project: detection.project,
|
|
20
|
+
packageJson: detection.packageJson
|
|
21
|
+
};
|
|
22
|
+
const findings = sortFindings(await runRules(rules, context));
|
|
23
|
+
return {
|
|
24
|
+
project: detection.project,
|
|
25
|
+
summary: summarizeFindings(findings),
|
|
26
|
+
findings,
|
|
27
|
+
metadata: {
|
|
28
|
+
scannedAt: new Date(startedAt).toISOString(),
|
|
29
|
+
durationMs: Date.now() - startedAt,
|
|
30
|
+
toolVersion: options.toolVersion ?? "0.0.0"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export async function resolveProjectPath(targetPath) {
|
|
35
|
+
const rootPath = path.resolve(targetPath);
|
|
36
|
+
await access(rootPath);
|
|
37
|
+
const rootStat = await stat(rootPath);
|
|
38
|
+
if (!rootStat.isDirectory()) {
|
|
39
|
+
throw new Error(`Scan target must be a directory: ${targetPath}`);
|
|
40
|
+
}
|
|
41
|
+
return rootPath;
|
|
42
|
+
}
|
|
43
|
+
async function runRules(rules, context) {
|
|
44
|
+
const findings = [];
|
|
45
|
+
for (const rule of rules) {
|
|
46
|
+
findings.push(...(await rule.scan(context)));
|
|
47
|
+
}
|
|
48
|
+
return findings;
|
|
49
|
+
}
|
|
50
|
+
function normalizeCategories(categories) {
|
|
51
|
+
return new Set((categories ?? []).map((category) => category.trim()).filter(Boolean));
|
|
52
|
+
}
|
|
53
|
+
function sortFindings(findings) {
|
|
54
|
+
return [...findings].sort((a, b) => {
|
|
55
|
+
const fileCompare = a.filePath.localeCompare(b.filePath);
|
|
56
|
+
if (fileCompare !== 0) {
|
|
57
|
+
return fileCompare;
|
|
58
|
+
}
|
|
59
|
+
return (a.line ?? 0) - (b.line ?? 0) || a.ruleId.localeCompare(b.ruleId);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,UAAkB,EAAE,UAAuB,EAAE;IAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE;QACzC,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,EAA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AAY,CAAC;AAiBxF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,WAAW,CAgBlE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAc1D"}
|
package/dist/score.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const SEVERITY_COUNTS = ["HIGH", "MEDIUM", "LOW", "INFO"];
|
|
2
|
+
const PENALTY = {
|
|
3
|
+
HIGH: 15,
|
|
4
|
+
MEDIUM: 7,
|
|
5
|
+
LOW: 3,
|
|
6
|
+
INFO: 0
|
|
7
|
+
};
|
|
8
|
+
const CONFIDENCE_MULTIPLIER = {
|
|
9
|
+
HIGH: 1,
|
|
10
|
+
MEDIUM: 0.7,
|
|
11
|
+
LOW: 0.4
|
|
12
|
+
};
|
|
13
|
+
export function summarizeFindings(findings) {
|
|
14
|
+
const counts = countBySeverity(findings);
|
|
15
|
+
const penalty = findings.reduce((total, finding) => {
|
|
16
|
+
return total + PENALTY[finding.severity] * CONFIDENCE_MULTIPLIER[finding.confidence];
|
|
17
|
+
}, 0);
|
|
18
|
+
const score = Math.max(0, Math.round(100 - penalty));
|
|
19
|
+
return {
|
|
20
|
+
score,
|
|
21
|
+
riskLevel: riskLevelForScore(score),
|
|
22
|
+
totalFindings: findings.length,
|
|
23
|
+
high: counts.HIGH,
|
|
24
|
+
medium: counts.MEDIUM,
|
|
25
|
+
low: counts.LOW,
|
|
26
|
+
info: counts.INFO
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function riskLevelForScore(score) {
|
|
30
|
+
if (score >= 90) {
|
|
31
|
+
return "excellent";
|
|
32
|
+
}
|
|
33
|
+
if (score >= 75) {
|
|
34
|
+
return "good";
|
|
35
|
+
}
|
|
36
|
+
if (score >= 60) {
|
|
37
|
+
return "medium";
|
|
38
|
+
}
|
|
39
|
+
if (score >= 40) {
|
|
40
|
+
return "high";
|
|
41
|
+
}
|
|
42
|
+
return "critical";
|
|
43
|
+
}
|
|
44
|
+
function countBySeverity(findings) {
|
|
45
|
+
return Object.fromEntries(SEVERITY_COUNTS.map((severity) => [severity, findings.filter((finding) => finding.severity === severity).length]));
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"score.js","sourceRoot":"","sources":["../src/score.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEtE,MAAM,OAAO,GAA6B;IACxC,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;CACR,CAAC;AAEF,MAAM,qBAAqB,GAA+B;IACxD,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,GAAG;IACX,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,QAAmB;IACnD,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACjD,OAAO,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvF,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IAErD,OAAO;QACL,KAAK;QACL,SAAS,EAAE,iBAAiB,CAAC,KAAK,CAAC;QACnC,aAAa,EAAE,QAAQ,CAAC,MAAM;QAC9B,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,eAAe,CAAC,QAAmB;IAC1C,OAAO,MAAM,CAAC,WAAW,CACvB,eAAe,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CACtF,CAAC;AAChC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type Severity = "HIGH" | "MEDIUM" | "LOW" | "INFO";
|
|
2
|
+
export type Confidence = "HIGH" | "MEDIUM" | "LOW";
|
|
3
|
+
export type RiskLevel = "excellent" | "good" | "medium" | "high" | "critical";
|
|
4
|
+
export type ProjectInfo = {
|
|
5
|
+
name?: string;
|
|
6
|
+
framework: "nextjs" | "react" | "node" | "unknown";
|
|
7
|
+
router?: "app" | "pages" | "mixed" | "unknown";
|
|
8
|
+
language: "typescript" | "javascript" | "mixed" | "unknown";
|
|
9
|
+
};
|
|
10
|
+
export type Finding = {
|
|
11
|
+
id: string;
|
|
12
|
+
ruleId: string;
|
|
13
|
+
title: string;
|
|
14
|
+
severity: Severity;
|
|
15
|
+
confidence: Confidence;
|
|
16
|
+
category: string;
|
|
17
|
+
filePath: string;
|
|
18
|
+
line?: number;
|
|
19
|
+
column?: number;
|
|
20
|
+
evidence?: string;
|
|
21
|
+
description: string;
|
|
22
|
+
recommendation: string;
|
|
23
|
+
references?: string[];
|
|
24
|
+
};
|
|
25
|
+
export type ScanSummary = {
|
|
26
|
+
score: number;
|
|
27
|
+
riskLevel: RiskLevel;
|
|
28
|
+
totalFindings: number;
|
|
29
|
+
high: number;
|
|
30
|
+
medium: number;
|
|
31
|
+
low: number;
|
|
32
|
+
info: number;
|
|
33
|
+
};
|
|
34
|
+
export type ScanResult = {
|
|
35
|
+
project: ProjectInfo;
|
|
36
|
+
summary: ScanSummary;
|
|
37
|
+
findings: Finding[];
|
|
38
|
+
metadata: {
|
|
39
|
+
scannedAt: string;
|
|
40
|
+
durationMs: number;
|
|
41
|
+
toolVersion: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type SourceFile = {
|
|
45
|
+
path: string;
|
|
46
|
+
absolutePath: string;
|
|
47
|
+
content: string;
|
|
48
|
+
lines: string[];
|
|
49
|
+
};
|
|
50
|
+
export type ScanContext = {
|
|
51
|
+
targetPath: string;
|
|
52
|
+
rootPath: string;
|
|
53
|
+
files: SourceFile[];
|
|
54
|
+
project: ProjectInfo;
|
|
55
|
+
packageJson?: {
|
|
56
|
+
name?: string;
|
|
57
|
+
dependencies: Record<string, string>;
|
|
58
|
+
devDependencies: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type Rule = {
|
|
62
|
+
id: string;
|
|
63
|
+
title: string;
|
|
64
|
+
severity: Severity;
|
|
65
|
+
category: string;
|
|
66
|
+
confidence?: Confidence;
|
|
67
|
+
scan(context: ScanContext): Promise<Finding[]> | Finding[];
|
|
68
|
+
};
|
|
69
|
+
export type ScanOptions = {
|
|
70
|
+
categories?: string[];
|
|
71
|
+
excludePaths?: string[];
|
|
72
|
+
rules?: Rule[];
|
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AO,EAAE,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@next-secure-check/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core scanning engine for next-secure-check",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nextjs",
|
|
7
|
+
"security",
|
|
8
|
+
"scanner",
|
|
9
|
+
"static-analysis",
|
|
10
|
+
"sast"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/SetraTheXX/next-secure-check.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -p tsconfig.json",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
38
|
+
"clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true});fs.rmSync('.tsbuildinfo',{force:true})\""
|
|
39
|
+
}
|
|
40
|
+
}
|