codecordon 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Glenn Dinkins
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,22 @@
1
+ # CodeCordon CLI
2
+
3
+ Run CodeCordon's deterministic security scanner from a terminal or CI pipeline.
4
+
5
+ ```bash
6
+ export CODECORDON_API_KEY="cc_live_..."
7
+ npx codecordon .
8
+ ```
9
+
10
+ Scan a public GitHub repository without cloning it:
11
+
12
+ ```bash
13
+ npx codecordon https://github.com/owner/repo --fail-on high
14
+ ```
15
+
16
+ The default gate fails when a critical finding is present. Use `--fail-on high`,
17
+ `--min-score 80`, or `--json` to fit the command into your pipeline. Local source
18
+ is compressed in memory; dependencies, build output, lockfiles, binaries, and
19
+ files larger than 512KB are excluded.
20
+
21
+ An API key and CodeCordon Pro plan are required for CI scans. A passing command
22
+ means the configured known-pattern gate passed. It is not a security certification.
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { main } from "../src/cli.js";
4
+
5
+ main(process.argv.slice(2)).then(
6
+ (code) => {
7
+ process.exitCode = code;
8
+ },
9
+ (error) => {
10
+ console.error(`CodeCordon error: ${error instanceof Error ? error.message : String(error)}`);
11
+ process.exitCode = 2;
12
+ },
13
+ );
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "codecordon",
3
+ "version": "0.1.0",
4
+ "description": "Scan AI-generated applications for known security mistakes from your terminal or CI pipeline.",
5
+ "type": "module",
6
+ "bin": {
7
+ "codecordon": "bin/codecordon.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "test": "node --test",
16
+ "check": "node --check bin/codecordon.js && node --check src/cli.js"
17
+ },
18
+ "engines": {
19
+ "node": ">=20"
20
+ },
21
+ "keywords": [
22
+ "security",
23
+ "static-analysis",
24
+ "vibe-coding",
25
+ "ai-code",
26
+ "ci"
27
+ ],
28
+ "license": "MIT",
29
+ "author": "Glenn Dinkins",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/fj8b85t9g6-blip/codecordon.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/fj8b85t9g6-blip/codecordon/issues"
36
+ },
37
+ "homepage": "https://codecordon.up.railway.app",
38
+ "dependencies": {
39
+ "adm-zip": "^0.6.0"
40
+ }
41
+ }
package/src/cli.js ADDED
@@ -0,0 +1,212 @@
1
+ import { lstatSync, readFileSync, readdirSync } from "node:fs";
2
+ import path from "node:path";
3
+ import AdmZip from "adm-zip";
4
+
5
+ const DEFAULT_URL = "https://codecordon.up.railway.app";
6
+ const MAX_ARCHIVE_BYTES = 50 * 1024 * 1024;
7
+ const MAX_FILES = 5000;
8
+ const SEVERITY_ORDER = ["critical", "high", "medium", "low"];
9
+ const SCANNABLE_EXTENSIONS = new Set([
10
+ ".c", ".cc", ".cpp", ".cs", ".dart", ".ex", ".exs", ".fs", ".fsx",
11
+ ".go", ".gradle", ".graphql", ".h", ".hcl", ".hpp", ".html", ".java",
12
+ ".js", ".json", ".jsx", ".kt", ".kts", ".lua", ".mjs", ".php", ".pl",
13
+ ".prisma", ".properties", ".py", ".rb", ".rs", ".scala", ".sh", ".sql",
14
+ ".svelte", ".swift", ".tf", ".toml", ".ts", ".tsx", ".vue", ".xml",
15
+ ".yaml", ".yml",
16
+ ]);
17
+ const IGNORED_DIRS = new Set([
18
+ ".git", ".next", ".turbo", ".venv", "DerivedData", "Pods", "__pycache__",
19
+ "build", "coverage", "dist", "node_modules", "out", "target", "vendor", "venv",
20
+ ]);
21
+
22
+ export function parseArgs(argv) {
23
+ const options = {
24
+ target: ".",
25
+ apiKey: process.env.CODECORDON_API_KEY ?? "",
26
+ baseUrl: process.env.CODECORDON_URL ?? DEFAULT_URL,
27
+ name: "",
28
+ format: "pretty",
29
+ failOn: "critical",
30
+ minScore: null,
31
+ help: false,
32
+ version: false,
33
+ };
34
+ const positionals = [];
35
+
36
+ for (let i = 0; i < argv.length; i++) {
37
+ const arg = argv[i];
38
+ if (arg === "--help" || arg === "-h") options.help = true;
39
+ else if (arg === "--version" || arg === "-v") options.version = true;
40
+ else if (arg === "--json") options.format = "json";
41
+ else if (arg === "--api-key") options.apiKey = requiredValue(argv, ++i, arg);
42
+ else if (arg === "--url") options.baseUrl = requiredValue(argv, ++i, arg);
43
+ else if (arg === "--name") options.name = requiredValue(argv, ++i, arg);
44
+ else if (arg === "--format") options.format = requiredValue(argv, ++i, arg);
45
+ else if (arg === "--fail-on") options.failOn = requiredValue(argv, ++i, arg);
46
+ else if (arg === "--min-score") options.minScore = Number(requiredValue(argv, ++i, arg));
47
+ else if (arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
48
+ else positionals.push(arg);
49
+ }
50
+
51
+ if (positionals.length > 1) throw new Error("Provide one local path or public GitHub URL.");
52
+ if (positionals[0]) options.target = positionals[0];
53
+ if (!new Set(["pretty", "json"]).has(options.format)) throw new Error("--format must be pretty or json.");
54
+ if (![...SEVERITY_ORDER, "none"].includes(options.failOn)) {
55
+ throw new Error("--fail-on must be critical, high, medium, low, or none.");
56
+ }
57
+ if (options.minScore !== null && (!Number.isFinite(options.minScore) || options.minScore < 0 || options.minScore > 100)) {
58
+ throw new Error("--min-score must be between 0 and 100.");
59
+ }
60
+ return options;
61
+ }
62
+
63
+ export function buildArchive(target) {
64
+ const root = path.resolve(target);
65
+ const stat = lstatSync(root);
66
+ if (!stat.isDirectory()) throw new Error("Local scan target must be a directory.");
67
+
68
+ const zip = new AdmZip();
69
+ const state = { files: 0, bytes: 0 };
70
+ addDirectory(zip, root, root, state);
71
+ if (state.files === 0) throw new Error("No scannable source files found.");
72
+ const buffer = zip.toBuffer();
73
+ if (buffer.length > MAX_ARCHIVE_BYTES) throw new Error("Compressed source archive exceeds 50MB.");
74
+ return { buffer, files: state.files };
75
+ }
76
+
77
+ export function gateReport(report, { failOn, minScore }) {
78
+ const reasons = [];
79
+ if (failOn !== "none") {
80
+ const cutoff = SEVERITY_ORDER.indexOf(failOn);
81
+ const failing = SEVERITY_ORDER.slice(0, cutoff + 1).filter((severity) => Number(report.summary?.[severity] ?? 0) > 0);
82
+ if (failing.length > 0) reasons.push(`found ${failing.join("/")} severity issues`);
83
+ }
84
+ if (minScore !== null && Number(report.score) < minScore) reasons.push(`score ${report.score} is below ${minScore}`);
85
+ return { passed: reasons.length === 0, reasons };
86
+ }
87
+
88
+ export function formatReport(report, gate) {
89
+ const counts = report.summary ?? {};
90
+ const lines = [
91
+ `CodeCordon: ${report.project ?? "project"}`,
92
+ `Grade ${report.grade} | ${report.score}/100 | ${report.filesScanned} files`,
93
+ `${counts.critical ?? 0} critical, ${counts.high ?? 0} high, ${counts.medium ?? 0} medium, ${counts.low ?? 0} low`,
94
+ ];
95
+ for (const finding of (report.findings ?? []).slice(0, 20)) {
96
+ lines.push(`[${String(finding.severity).toUpperCase()}] ${finding.ruleId} ${finding.file}:${finding.line} - ${finding.title}`);
97
+ }
98
+ if ((report.findings?.length ?? 0) > 20) lines.push(`...and ${report.findings.length - 20} more findings`);
99
+ lines.push(gate.passed ? "Gate: PASS" : `Gate: FAIL (${gate.reasons.join("; ")})`);
100
+ lines.push("A passing scan means no configured known-pattern gate failed; it is not a security certification.");
101
+ return lines.join("\n");
102
+ }
103
+
104
+ export async function main(argv, dependencies = {}) {
105
+ let options;
106
+ try {
107
+ options = parseArgs(argv);
108
+ } catch (error) {
109
+ console.error(error instanceof Error ? error.message : String(error));
110
+ console.error("Run codecordon --help for usage.");
111
+ return 2;
112
+ }
113
+
114
+ if (options.help) {
115
+ console.log(helpText());
116
+ return 0;
117
+ }
118
+ if (options.version) {
119
+ console.log("0.1.0");
120
+ return 0;
121
+ }
122
+ if (!options.apiKey) {
123
+ console.error("Set CODECORDON_API_KEY or pass --api-key. Create an API key in CodeCordon Settings.");
124
+ return 2;
125
+ }
126
+
127
+ const githubUrl = parseGithubTarget(options.target);
128
+ const projectName = options.name || inferProjectName(options.target, githubUrl);
129
+ const form = new FormData();
130
+ form.set("name", projectName);
131
+ if (githubUrl) {
132
+ form.set("github_url", githubUrl);
133
+ } else {
134
+ let archive;
135
+ try {
136
+ archive = buildArchive(options.target);
137
+ } catch (error) {
138
+ console.error(error instanceof Error ? error.message : String(error));
139
+ return 2;
140
+ }
141
+ form.set("zip", new Blob([archive.buffer], { type: "application/zip" }), `${projectName}.zip`);
142
+ }
143
+
144
+ const fetchImpl = dependencies.fetch ?? fetch;
145
+ let response;
146
+ try {
147
+ response = await fetchImpl(`${options.baseUrl.replace(/\/$/, "")}/api/v1/scans`, {
148
+ method: "POST",
149
+ headers: { "X-Api-Key": options.apiKey },
150
+ body: form,
151
+ signal: AbortSignal.timeout(120_000),
152
+ });
153
+ } catch (error) {
154
+ console.error(`Could not reach CodeCordon: ${error instanceof Error ? error.message : String(error)}`);
155
+ return 2;
156
+ }
157
+
158
+ const payload = await response.json().catch(() => ({ error: `HTTP ${response.status}` }));
159
+ if (!response.ok) {
160
+ console.error(`CodeCordon API error (${response.status}): ${payload.error ?? "request failed"}`);
161
+ return 2;
162
+ }
163
+ const gate = gateReport(payload, options);
164
+ console.log(options.format === "json" ? JSON.stringify({ ...payload, gate }, null, 2) : formatReport(payload, gate));
165
+ return gate.passed ? 0 : 1;
166
+ }
167
+
168
+ function addDirectory(zip, root, current, state) {
169
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
170
+ if (entry.isSymbolicLink()) continue;
171
+ if (entry.isDirectory() && IGNORED_DIRS.has(entry.name)) continue;
172
+ const fullPath = path.join(current, entry.name);
173
+ if (entry.isDirectory()) {
174
+ addDirectory(zip, root, fullPath, state);
175
+ continue;
176
+ }
177
+ if (!entry.isFile() || !isScannable(entry.name)) continue;
178
+ const data = readFileSync(fullPath);
179
+ if (data.length > 512 * 1024) continue;
180
+ state.files += 1;
181
+ state.bytes += data.length;
182
+ if (state.files > MAX_FILES || state.bytes > MAX_ARCHIVE_BYTES) throw new Error("Source exceeds the 5,000-file or 50MB scan limit.");
183
+ zip.addFile(path.relative(root, fullPath).split(path.sep).join("/"), data);
184
+ }
185
+ }
186
+
187
+ function isScannable(filename) {
188
+ const lower = filename.toLowerCase();
189
+ if (lower === ".gitignore" || lower === "dockerfile" || lower.endsWith(".rules")) return true;
190
+ if (lower === ".env" || lower.startsWith(".env.")) return !lower.includes("example");
191
+ if (lower.endsWith(".lock") || lower.endsWith(".min.js")) return false;
192
+ return SCANNABLE_EXTENSIONS.has(path.extname(lower));
193
+ }
194
+
195
+ function parseGithubTarget(target) {
196
+ return /^(?:https?:\/\/)?(?:www\.)?github\.com\/[\w.-]+\/[\w.-]+(?:\.git)?(?:\/tree\/[\w./-]+)?\/?$/i.test(target) ? target : null;
197
+ }
198
+
199
+ function inferProjectName(target, githubUrl) {
200
+ if (githubUrl) return githubUrl.replace(/\/$/, "").split("/").at(-1).replace(/\.git$/, "");
201
+ return path.basename(path.resolve(target));
202
+ }
203
+
204
+ function requiredValue(argv, index, option) {
205
+ const value = argv[index];
206
+ if (!value || value.startsWith("-")) throw new Error(`${option} requires a value.`);
207
+ return value;
208
+ }
209
+
210
+ function helpText() {
211
+ return `CodeCordon CLI\n\nUsage:\n codecordon [path|github-url] [options]\n\nOptions:\n --name <name> Project name shown in CodeCordon\n --api-key <key> API key (prefer CODECORDON_API_KEY)\n --url <url> API base URL (default: ${DEFAULT_URL})\n --fail-on <severity> critical, high, medium, low, or none\n --min-score <0-100> Also fail below this score\n --format <pretty|json> Output format\n --json Shortcut for --format json\n -h, --help Show help\n -v, --version Show version\n\nExamples:\n CODECORDON_API_KEY=cc_live_... npx codecordon .\n npx codecordon https://github.com/owner/repo --fail-on high\n npx codecordon . --json --min-score 80`;
212
+ }