prepublic 0.0.0-stage → 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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +164 -2
- package/SECURITY.md +18 -0
- package/bin/prepublic.js +12 -0
- package/package.json +50 -4
- package/scripts/make-examples.mjs +200 -0
- package/src/checks/history.js +210 -0
- package/src/checks/project.js +351 -0
- package/src/checks/worktree.js +268 -0
- package/src/cli.js +203 -0
- package/src/config.js +59 -0
- package/src/findings.js +53 -0
- package/src/git.js +164 -0
- package/src/gitleaks.js +118 -0
- package/src/index.js +5 -0
- package/src/report/fonts/OFL.txt +192 -0
- package/src/report/fonts/ibm-plex-mono-latin-400.woff2 +0 -0
- package/src/report/fonts/ibm-plex-mono-latin-500.woff2 +0 -0
- package/src/report/fonts/ibm-plex-sans-latin-wght.woff2 +0 -0
- package/src/report/html.js +58 -0
- package/src/report/markdown.js +63 -0
- package/src/report/ui/app.js +590 -0
- package/src/report/ui/styles.css +356 -0
- package/src/report/ui/template.html +87 -0
- package/src/rules/files.js +78 -0
- package/src/rules/personal.js +76 -0
- package/src/rules/secrets.js +241 -0
- package/src/scan.js +221 -0
- package/src/version.js +2 -0
package/src/git.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Hardened, read-only Git invocation.
|
|
2
|
+
//
|
|
3
|
+
// Prepublic is often pointed at repositories the user has not audited yet, so
|
|
4
|
+
// every Git call disables repository-configurable code execution paths that
|
|
5
|
+
// read-only commands could otherwise trigger (fsmonitor hooks, textconv and
|
|
6
|
+
// external diff drivers, pagers, signature verification) and never takes
|
|
7
|
+
// optional locks, so the index is not rewritten.
|
|
8
|
+
|
|
9
|
+
import { spawn } from 'node:child_process';
|
|
10
|
+
|
|
11
|
+
const HARDENING = [
|
|
12
|
+
'-c', 'core.fsmonitor=false',
|
|
13
|
+
'-c', 'core.untrackedCache=false',
|
|
14
|
+
'-c', 'core.pager=cat',
|
|
15
|
+
'-c', 'core.quotePath=false',
|
|
16
|
+
'-c', 'color.ui=false',
|
|
17
|
+
'-c', 'log.showSignature=false',
|
|
18
|
+
'-c', 'protocol.allow=never',
|
|
19
|
+
'-c', 'i18n.logOutputEncoding=UTF-8',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function gitEnv() {
|
|
23
|
+
const env = { ...process.env };
|
|
24
|
+
for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_EXTERNAL_DIFF', 'GIT_PAGER', 'GIT_CEILING_DIRECTORIES']) {
|
|
25
|
+
delete env[key];
|
|
26
|
+
}
|
|
27
|
+
env.GIT_OPTIONAL_LOCKS = '0';
|
|
28
|
+
env.GIT_TERMINAL_PROMPT = '0';
|
|
29
|
+
env.GIT_PAGER = 'cat';
|
|
30
|
+
env.PAGER = 'cat';
|
|
31
|
+
env.LC_ALL = 'C';
|
|
32
|
+
return env;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class GitError extends Error {
|
|
36
|
+
constructor(message, { code, stderr } = {}) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = 'GitError';
|
|
39
|
+
this.code = code;
|
|
40
|
+
this.stderr = stderr;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Run git and collect stdout as a Buffer.
|
|
46
|
+
* @param {string[]} args
|
|
47
|
+
* @param {{cwd: string, input?: string|Buffer, allowFailure?: boolean, maxBytes?: number}} opts
|
|
48
|
+
*/
|
|
49
|
+
export function git(args, { cwd, input, allowFailure = false, maxBytes = 256 * 1024 * 1024 } = {}) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
let child;
|
|
52
|
+
try {
|
|
53
|
+
child = spawn('git', [...HARDENING, ...args], { cwd, env: gitEnv(), windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
54
|
+
} catch (err) {
|
|
55
|
+
reject(new GitError(`Unable to start git: ${err.message}`));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const out = [];
|
|
59
|
+
let outLen = 0;
|
|
60
|
+
let err = '';
|
|
61
|
+
let truncated = false;
|
|
62
|
+
child.stdout.on('data', (chunk) => {
|
|
63
|
+
if (truncated) return;
|
|
64
|
+
outLen += chunk.length;
|
|
65
|
+
if (outLen > maxBytes) {
|
|
66
|
+
truncated = true;
|
|
67
|
+
child.kill();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
out.push(chunk);
|
|
71
|
+
});
|
|
72
|
+
child.stderr.on('data', (chunk) => {
|
|
73
|
+
if (err.length < 8192) err += chunk.toString('utf8');
|
|
74
|
+
});
|
|
75
|
+
child.on('error', (e) => reject(new GitError(e.code === 'ENOENT' ? 'Git is not installed or not on PATH.' : `git failed: ${e.message}`)));
|
|
76
|
+
child.on('close', (code) => {
|
|
77
|
+
const stdout = Buffer.concat(out);
|
|
78
|
+
if (code !== 0 && !truncated && !allowFailure) {
|
|
79
|
+
reject(new GitError(`git ${args[0]} failed: ${err.trim() || `exit code ${code}`}`, { code, stderr: err }));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
resolve({ stdout, code, stderr: err, truncated });
|
|
83
|
+
});
|
|
84
|
+
if (input !== undefined) child.stdin.end(input);
|
|
85
|
+
else child.stdin.end();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function gitText(args, opts) {
|
|
90
|
+
const { stdout } = await git(args, opts);
|
|
91
|
+
return stdout.toString('utf8');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function gitNulList(args, opts) {
|
|
95
|
+
const text = await gitText(args, opts);
|
|
96
|
+
return text.split('\0').filter(Boolean);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Stream git stdout line by line. `onLine` may return false to stop early.
|
|
101
|
+
* Resolves with { bytes, truncated }.
|
|
102
|
+
*/
|
|
103
|
+
export function gitLines(args, { cwd, maxBytes = Infinity, onLine }) {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
const child = spawn('git', [...HARDENING, ...args], { cwd, env: gitEnv(), windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
106
|
+
let rest = '';
|
|
107
|
+
let bytes = 0;
|
|
108
|
+
let stopped = false;
|
|
109
|
+
let truncated = false;
|
|
110
|
+
let err = '';
|
|
111
|
+
const decoder = new TextDecoder('utf-8');
|
|
112
|
+
const stop = (isTruncation) => {
|
|
113
|
+
if (stopped) return;
|
|
114
|
+
stopped = true;
|
|
115
|
+
truncated = isTruncation;
|
|
116
|
+
child.stdout.removeAllListeners('data');
|
|
117
|
+
child.kill();
|
|
118
|
+
};
|
|
119
|
+
child.stdout.on('data', (chunk) => {
|
|
120
|
+
bytes += chunk.length;
|
|
121
|
+
rest += decoder.decode(chunk, { stream: true });
|
|
122
|
+
let idx;
|
|
123
|
+
while ((idx = rest.indexOf('\n')) !== -1) {
|
|
124
|
+
const line = rest.slice(0, idx);
|
|
125
|
+
rest = rest.slice(idx + 1);
|
|
126
|
+
if (onLine(line.endsWith('\r') ? line.slice(0, -1) : line) === false) {
|
|
127
|
+
stop(false);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (bytes > maxBytes) stop(true);
|
|
132
|
+
});
|
|
133
|
+
child.stderr.on('data', (chunk) => {
|
|
134
|
+
if (err.length < 8192) err += chunk.toString('utf8');
|
|
135
|
+
});
|
|
136
|
+
child.on('error', (e) => reject(new GitError(`git failed: ${e.message}`)));
|
|
137
|
+
child.on('close', (code) => {
|
|
138
|
+
if (!stopped && rest) onLine(rest);
|
|
139
|
+
if (code !== 0 && !stopped) {
|
|
140
|
+
reject(new GitError(`git ${args[0]} failed: ${err.trim() || `exit code ${code}`}`, { code, stderr: err }));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
resolve({ bytes, truncated });
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Resolve the repository root, or throw a friendly error. */
|
|
149
|
+
export async function resolveRepo(dir) {
|
|
150
|
+
try {
|
|
151
|
+
const top = (await gitText(['rev-parse', '--show-toplevel'], { cwd: dir })).trim();
|
|
152
|
+
if (!top) throw new GitError('Not a Git repository.');
|
|
153
|
+
return top;
|
|
154
|
+
} catch (err) {
|
|
155
|
+
const msg = String(err.stderr || err.message || '');
|
|
156
|
+
if (/dubious ownership/i.test(msg)) {
|
|
157
|
+
throw new GitError('Git refused this repository because it is owned by another user ("dubious ownership"). Review it, then mark it with `git config --global --add safe.directory <path>` if you trust it.');
|
|
158
|
+
}
|
|
159
|
+
if (/not a git repository/i.test(msg)) {
|
|
160
|
+
throw new GitError('Not a Git repository. Point Prepublic at a folder that contains a .git directory.');
|
|
161
|
+
}
|
|
162
|
+
throw err;
|
|
163
|
+
}
|
|
164
|
+
}
|
package/src/gitleaks.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Optional Gitleaks integration. Gitleaks is only used when it is already
|
|
2
|
+
// installed (or a path is given); Prepublic never downloads it.
|
|
3
|
+
//
|
|
4
|
+
// Gitleaks runs with --redact, writes its report to a private temp directory
|
|
5
|
+
// that is deleted afterwards, and Prepublic drops the Secret/Match fields from
|
|
6
|
+
// every result anyway, so raw values never reach a Prepublic report.
|
|
7
|
+
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { makeFinding, REFS } from './findings.js';
|
|
13
|
+
import { maskPersonalPaths } from './rules/personal.js';
|
|
14
|
+
|
|
15
|
+
function run(cmd, args, { timeoutMs }) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
let child;
|
|
18
|
+
try {
|
|
19
|
+
child = spawn(cmd, args, { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' } });
|
|
20
|
+
} catch (err) {
|
|
21
|
+
resolve({ error: err });
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let stdout = '';
|
|
25
|
+
let stderr = '';
|
|
26
|
+
const timer = setTimeout(() => { child.kill(); resolve({ error: new Error('timed out') }); }, timeoutMs);
|
|
27
|
+
child.stdout.on('data', (c) => { if (stdout.length < 65536) stdout += c; });
|
|
28
|
+
child.stderr.on('data', (c) => { if (stderr.length < 65536) stderr += c; });
|
|
29
|
+
child.on('error', (error) => { clearTimeout(timer); resolve({ error }); });
|
|
30
|
+
child.on('close', (code) => { clearTimeout(timer); resolve({ code, stdout, stderr }); });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {string} root repository root
|
|
36
|
+
* @param {{mode: 'auto'|'off'|'require', command?: string[], timeoutMs?: number}} opts
|
|
37
|
+
* `command` is the executable plus any leading arguments (defaults to ['gitleaks']).
|
|
38
|
+
*/
|
|
39
|
+
export async function runGitleaks(root, { mode = 'auto', command = ['gitleaks'], timeoutMs = 10 * 60 * 1000 } = {}) {
|
|
40
|
+
const status = { mode, available: false, ran: false, version: null, findings: 0, error: null };
|
|
41
|
+
if (mode === 'off') return { status, results: [] };
|
|
42
|
+
const [bin, ...pre] = command;
|
|
43
|
+
|
|
44
|
+
const ver = await run(bin, [...pre, 'version'], { timeoutMs: 15000 });
|
|
45
|
+
if (ver.error || ver.code !== 0) {
|
|
46
|
+
status.error = ver.error?.code === 'ENOENT' || /not found|ENOENT/i.test(String(ver.error?.message)) ? 'not installed' : `unavailable (${(ver.error?.message || ver.stderr || `exit ${ver.code}`).toString().trim().slice(0, 120)})`;
|
|
47
|
+
return { status, results: [] };
|
|
48
|
+
}
|
|
49
|
+
status.available = true;
|
|
50
|
+
status.version = ver.stdout.trim().split('\n')[0].replace(/^v/, '').slice(0, 40);
|
|
51
|
+
|
|
52
|
+
const dir = await mkdtemp(join(tmpdir(), 'prepublic-gl-'));
|
|
53
|
+
const reportPath = join(dir, 'report.json');
|
|
54
|
+
try {
|
|
55
|
+
const res = await run(bin, [
|
|
56
|
+
...pre, 'git', '--redact', '--no-banner', '--exit-code', '0', '--log-level', 'error',
|
|
57
|
+
'--report-format', 'json', '--report-path', reportPath, root,
|
|
58
|
+
], { timeoutMs });
|
|
59
|
+
if (res.error || res.code !== 0) {
|
|
60
|
+
status.error = `scan failed (${(res.error?.message || res.stderr || `exit ${res.code}`).toString().trim().split('\n')[0].slice(0, 160)})`;
|
|
61
|
+
return { status, results: [] };
|
|
62
|
+
}
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(await readFile(reportPath, 'utf8'));
|
|
66
|
+
} catch (err) {
|
|
67
|
+
status.error = `could not read report (${err.message.slice(0, 80)})`;
|
|
68
|
+
return { status, results: [] };
|
|
69
|
+
}
|
|
70
|
+
if (!Array.isArray(parsed)) parsed = [];
|
|
71
|
+
status.ran = true;
|
|
72
|
+
// Keep only non-sensitive metadata. Secret, Match, Author, Email, Message and Line are discarded.
|
|
73
|
+
const results = parsed.map((r) => ({
|
|
74
|
+
ruleId: String(r.RuleID || 'unknown').slice(0, 80),
|
|
75
|
+
description: String(r.Description || '').slice(0, 200),
|
|
76
|
+
file: String(r.File || ''),
|
|
77
|
+
line: Number.isInteger(r.StartLine) ? r.StartLine : null,
|
|
78
|
+
commit: typeof r.Commit === 'string' && /^[0-9a-f]{7,64}$/i.test(r.Commit) ? r.Commit.slice(0, 7) : null,
|
|
79
|
+
entropy: typeof r.Entropy === 'number' ? Math.round(r.Entropy * 100) / 100 : null,
|
|
80
|
+
}));
|
|
81
|
+
status.findings = results.length;
|
|
82
|
+
return { status, results };
|
|
83
|
+
} finally {
|
|
84
|
+
await rm(dir, { recursive: true, force: true });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Turn Gitleaks results into Prepublic findings, grouped per rule and file. */
|
|
89
|
+
export function gitleaksFindings(results, { trackedSet, root }) {
|
|
90
|
+
const groups = new Map();
|
|
91
|
+
for (const r of results) {
|
|
92
|
+
let file = r.file.replace(/\\/g, '/');
|
|
93
|
+
const rootFwd = root.replace(/\\/g, '/');
|
|
94
|
+
if (file.startsWith(`${rootFwd}/`)) file = file.slice(rootFwd.length + 1);
|
|
95
|
+
file = maskPersonalPaths(file);
|
|
96
|
+
const key = `${r.ruleId}|${file}`;
|
|
97
|
+
if (!groups.has(key)) groups.set(key, { ...r, file, locations: [], commits: new Set() });
|
|
98
|
+
const g = groups.get(key);
|
|
99
|
+
g.locations.push({ path: file, line: r.line ?? undefined, commit: r.commit ?? undefined });
|
|
100
|
+
if (r.commit) g.commits.add(r.commit);
|
|
101
|
+
}
|
|
102
|
+
return [...groups.values()].map((g) => {
|
|
103
|
+
const current = trackedSet.has(g.file);
|
|
104
|
+
return makeFinding({
|
|
105
|
+
ruleId: `gitleaks/${g.ruleId}`, category: current ? 'secrets' : 'history', severity: 'high', confidence: 'medium', source: 'gitleaks',
|
|
106
|
+
title: g.description || `Gitleaks: ${g.ruleId}`,
|
|
107
|
+
summary: `Gitleaks rule "${g.ruleId}" matched ${g.locations.length} time${g.locations.length > 1 ? 's' : ''} in ${g.file} across ${g.commits.size || 1} commit${g.commits.size > 1 ? 's' : ''}${current ? '' : ' (file no longer tracked)'}.`,
|
|
108
|
+
why: 'Gitleaks scans the full history with a large, maintained rule set. Its matches are strong signals but may include false positives.',
|
|
109
|
+
actions: [
|
|
110
|
+
'Verify the match locally with `gitleaks git` (values are not included in this report).',
|
|
111
|
+
'If real: rotate the credential, then remove it from the files and, if needed, from history.',
|
|
112
|
+
'If a false positive: add a `gitleaks:allow` comment or a .gitleaksignore entry.',
|
|
113
|
+
],
|
|
114
|
+
commands: ['gitleaks git --redact -v .'],
|
|
115
|
+
locations: g.locations, references: [REFS.gitleaks, REFS.rotate], key: `${g.ruleId}|${g.file}`,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { scanRepository, sanitizeReport, DEFAULTS } from './scan.js';
|
|
2
|
+
export { renderMarkdown } from './report/markdown.js';
|
|
3
|
+
export { renderHtml } from './report/html.js';
|
|
4
|
+
export { findSecretsInLine, redactLine, SECRET_RULES } from './rules/secrets.js';
|
|
5
|
+
export { VERSION } from './version.js';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Fonts embedded in Prepublic HTML reports (latin subsets, via Fontsource):
|
|
2
|
+
IBM Plex Sans (variable) and IBM Plex Mono 400/500 by IBM Corp., licensed under the SIL Open Font License 1.1.
|
|
3
|
+
|
|
4
|
+
===== IBM Plex Sans =====
|
|
5
|
+
Copyright 2019 IBM Corp. All rights reserved. IBMPlexSans-Italic[wdth,wght].ttf: Copyright 2019 IBM Corp. All rights reserved.
|
|
6
|
+
|
|
7
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
8
|
+
This license is copied below, and is also available with a FAQ at:
|
|
9
|
+
http://scripts.sil.org/OFL
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
-----------------------------------------------------------
|
|
13
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
14
|
+
-----------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
PREAMBLE
|
|
17
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
18
|
+
development of collaborative font projects, to support the font creation
|
|
19
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
20
|
+
open framework in which fonts may be shared and improved in partnership
|
|
21
|
+
with others.
|
|
22
|
+
|
|
23
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
24
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
25
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
26
|
+
redistributed and/or sold with any software provided that any reserved
|
|
27
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
28
|
+
however, cannot be released under any other type of license. The
|
|
29
|
+
requirement for fonts to remain under this license does not apply
|
|
30
|
+
to any document created using the fonts or their derivatives.
|
|
31
|
+
|
|
32
|
+
DEFINITIONS
|
|
33
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
34
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
35
|
+
include source files, build scripts and documentation.
|
|
36
|
+
|
|
37
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
38
|
+
copyright statement(s).
|
|
39
|
+
|
|
40
|
+
"Original Version" refers to the collection of Font Software components as
|
|
41
|
+
distributed by the Copyright Holder(s).
|
|
42
|
+
|
|
43
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
44
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
45
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
46
|
+
new environment.
|
|
47
|
+
|
|
48
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
49
|
+
writer or other person who contributed to the Font Software.
|
|
50
|
+
|
|
51
|
+
PERMISSION & CONDITIONS
|
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
53
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
54
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
55
|
+
Software, subject to the following conditions:
|
|
56
|
+
|
|
57
|
+
1) Neither the Font Software nor any of its individual components,
|
|
58
|
+
in Original or Modified Versions, may be sold by itself.
|
|
59
|
+
|
|
60
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
61
|
+
redistributed and/or sold with any software, provided that each copy
|
|
62
|
+
contains the above copyright notice and this license. These can be
|
|
63
|
+
included either as stand-alone text files, human-readable headers or
|
|
64
|
+
in the appropriate machine-readable metadata fields within text or
|
|
65
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
66
|
+
|
|
67
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
68
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
69
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
70
|
+
presented to the users.
|
|
71
|
+
|
|
72
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
73
|
+
Software shall not be used to promote, endorse or advertise any
|
|
74
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
75
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
76
|
+
permission.
|
|
77
|
+
|
|
78
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
79
|
+
must be distributed entirely under this license, and must not be
|
|
80
|
+
distributed under any other license. The requirement for fonts to
|
|
81
|
+
remain under this license does not apply to any document created
|
|
82
|
+
using the Font Software.
|
|
83
|
+
|
|
84
|
+
TERMINATION
|
|
85
|
+
This license becomes null and void if any of the above conditions are
|
|
86
|
+
not met.
|
|
87
|
+
|
|
88
|
+
DISCLAIMER
|
|
89
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
90
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
91
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
92
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
93
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
94
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
95
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
96
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
97
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
98
|
+
|
|
99
|
+
===== IBM Plex Mono =====
|
|
100
|
+
Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-ThinItalic.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-ExtraLight.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-ExtraLightItalic.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-Light.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-LightItalic.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-Regular.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-Italic.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-Medium.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-MediumItalic.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-SemiBold.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-SemiBoldItalic.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-Bold.ttf: Copyright 2017 IBM Corp. All rights reserved. IBMPlexMono-BoldItalic.ttf: Copyright 2017 IBM Corp. All rights reserved.
|
|
101
|
+
|
|
102
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
103
|
+
This license is copied below, and is also available with a FAQ at:
|
|
104
|
+
http://scripts.sil.org/OFL
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
-----------------------------------------------------------
|
|
108
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
109
|
+
-----------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
PREAMBLE
|
|
112
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
113
|
+
development of collaborative font projects, to support the font creation
|
|
114
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
115
|
+
open framework in which fonts may be shared and improved in partnership
|
|
116
|
+
with others.
|
|
117
|
+
|
|
118
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
119
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
120
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
121
|
+
redistributed and/or sold with any software provided that any reserved
|
|
122
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
123
|
+
however, cannot be released under any other type of license. The
|
|
124
|
+
requirement for fonts to remain under this license does not apply
|
|
125
|
+
to any document created using the fonts or their derivatives.
|
|
126
|
+
|
|
127
|
+
DEFINITIONS
|
|
128
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
129
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
130
|
+
include source files, build scripts and documentation.
|
|
131
|
+
|
|
132
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
133
|
+
copyright statement(s).
|
|
134
|
+
|
|
135
|
+
"Original Version" refers to the collection of Font Software components as
|
|
136
|
+
distributed by the Copyright Holder(s).
|
|
137
|
+
|
|
138
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
139
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
140
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
141
|
+
new environment.
|
|
142
|
+
|
|
143
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
144
|
+
writer or other person who contributed to the Font Software.
|
|
145
|
+
|
|
146
|
+
PERMISSION & CONDITIONS
|
|
147
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
148
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
149
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
150
|
+
Software, subject to the following conditions:
|
|
151
|
+
|
|
152
|
+
1) Neither the Font Software nor any of its individual components,
|
|
153
|
+
in Original or Modified Versions, may be sold by itself.
|
|
154
|
+
|
|
155
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
156
|
+
redistributed and/or sold with any software, provided that each copy
|
|
157
|
+
contains the above copyright notice and this license. These can be
|
|
158
|
+
included either as stand-alone text files, human-readable headers or
|
|
159
|
+
in the appropriate machine-readable metadata fields within text or
|
|
160
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
161
|
+
|
|
162
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
163
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
164
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
165
|
+
presented to the users.
|
|
166
|
+
|
|
167
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
168
|
+
Software shall not be used to promote, endorse or advertise any
|
|
169
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
170
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
171
|
+
permission.
|
|
172
|
+
|
|
173
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
174
|
+
must be distributed entirely under this license, and must not be
|
|
175
|
+
distributed under any other license. The requirement for fonts to
|
|
176
|
+
remain under this license does not apply to any document created
|
|
177
|
+
using the Font Software.
|
|
178
|
+
|
|
179
|
+
TERMINATION
|
|
180
|
+
This license becomes null and void if any of the above conditions are
|
|
181
|
+
not met.
|
|
182
|
+
|
|
183
|
+
DISCLAIMER
|
|
184
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
185
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
186
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
187
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
188
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
189
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
190
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
191
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
192
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Self-contained HTML report: one file, no external resources, strict CSP
|
|
2
|
+
// (scripts and styles allowed only by hash), data embedded as inert JSON.
|
|
3
|
+
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
import { renderMarkdown } from './markdown.js';
|
|
9
|
+
|
|
10
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const UI = join(HERE, 'ui');
|
|
12
|
+
const load = (f) => readFileSync(join(UI, f), 'utf8');
|
|
13
|
+
const sha = (s) => `'sha256-${createHash('sha256').update(s, 'utf8').digest('base64')}'`;
|
|
14
|
+
|
|
15
|
+
// IBM Plex (SIL OFL 1.1, see fonts/OFL.txt) is embedded as data URIs so the
|
|
16
|
+
// report renders identically offline and never requests a font.
|
|
17
|
+
const FONTS = [
|
|
18
|
+
['Prepublic Sans', 'ibm-plex-sans-latin-wght.woff2', '100 700'],
|
|
19
|
+
['Prepublic Mono', 'ibm-plex-mono-latin-400.woff2', '400'],
|
|
20
|
+
['Prepublic Mono', 'ibm-plex-mono-latin-500.woff2', '500 700'],
|
|
21
|
+
];
|
|
22
|
+
let fontCss;
|
|
23
|
+
function fontFaces() {
|
|
24
|
+
fontCss ??= FONTS.map(([family, file, weight]) => {
|
|
25
|
+
const b64 = readFileSync(join(HERE, 'fonts', file)).toString('base64');
|
|
26
|
+
return `@font-face{font-family:"${family}";src:url(data:font/woff2;base64,${b64}) format("woff2");font-weight:${weight};font-style:normal;font-display:swap}`;
|
|
27
|
+
}).join('\n');
|
|
28
|
+
return fontCss;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Serialize JSON so it can never terminate the surrounding <script> element. */
|
|
32
|
+
export function safeJson(value) {
|
|
33
|
+
return JSON.stringify(value)
|
|
34
|
+
.replace(/</g, '\\u003c')
|
|
35
|
+
.replace(/>/g, '\\u003e')
|
|
36
|
+
.replace(/&/g, '\\u0026')
|
|
37
|
+
.replace(new RegExp(String.fromCharCode(0x2028), 'g'), '\\u2028')
|
|
38
|
+
.replace(new RegExp(String.fromCharCode(0x2029), 'g'), '\\u2029');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function renderHtml(report) {
|
|
42
|
+
const template = load('template.html');
|
|
43
|
+
const styles = `${fontFaces()}\n${load('styles.css')}`;
|
|
44
|
+
const script = load('app.js');
|
|
45
|
+
const csp = [
|
|
46
|
+
"default-src 'none'",
|
|
47
|
+
`style-src ${sha(styles)}`,
|
|
48
|
+
`script-src ${sha(script)}`,
|
|
49
|
+
'img-src data:',
|
|
50
|
+
'font-src data:',
|
|
51
|
+
"base-uri 'none'",
|
|
52
|
+
"form-action 'none'",
|
|
53
|
+
].join('; ');
|
|
54
|
+
const data = safeJson({ report, markdown: renderMarkdown(report) });
|
|
55
|
+
const parts = { CSP: csp, STYLES: styles, DATA: data, SCRIPT: script };
|
|
56
|
+
// Single pass, so inserted content is never re-scanned for placeholders.
|
|
57
|
+
return template.replace(/__(CSP|STYLES|DATA|SCRIPT)__/g, (_, k) => parts[k]);
|
|
58
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Shareable Markdown report. Input is an already-sanitized report model.
|
|
2
|
+
|
|
3
|
+
const ICON = { critical: '🔴', high: '🟠', medium: '🟡', low: '🔵', info: '⚪' };
|
|
4
|
+
const STATUS = { pass: '✅', fail: '❌', warn: '⚠️', manual: '👀', skipped: '⏭️' };
|
|
5
|
+
|
|
6
|
+
const code = (s) => `\`${String(s).replace(/`/g, "'")}\``;
|
|
7
|
+
const text = (s) => String(s).replace(/([\\<>|])/g, '\\$1').replace(/\r?\n/g, ' ');
|
|
8
|
+
const loc = (l) => code(`${l.path}${l.line ? `:${l.line}` : ''}`) + (l.commit ? ` @ ${code(l.commit)}` : '') + (l.note ? ` (${text(l.note)})` : '');
|
|
9
|
+
|
|
10
|
+
export function renderMarkdown(r) {
|
|
11
|
+
const out = [];
|
|
12
|
+
const meta = [r.repo.branch && `branch ${code(r.repo.branch)}`, r.repo.head && `commit ${code(r.repo.head)}`, `${r.repo.trackedFiles} tracked files`].filter(Boolean).join(' · ');
|
|
13
|
+
out.push(`# Prepublic report: ${text(r.repo.name)}`, '');
|
|
14
|
+
out.push(`${meta} `, `Generated ${r.generatedAt} by Prepublic ${r.tool.version}. Read-only, local scan.`, '');
|
|
15
|
+
out.push(`## ${r.verdict.label} · score ${r.score}/100`, '');
|
|
16
|
+
out.push(`${r.verdict.blockers} blocker${r.verdict.blockers === 1 ? '' : 's'} (critical/high) · ${r.verdict.toReview} to review (medium). `, `> ${r.verdict.note}`, '');
|
|
17
|
+
out.push('| Severity | Findings |', '|---|---:|');
|
|
18
|
+
for (const [s, n] of Object.entries(r.counts)) out.push(`| ${ICON[s]} ${s} | ${n} |`);
|
|
19
|
+
out.push('');
|
|
20
|
+
|
|
21
|
+
out.push('## Publication checklist', '');
|
|
22
|
+
for (const c of r.checklist) out.push(`- ${STATUS[c.status]} **${text(c.label)}**: ${text(c.detail || c.status)}`);
|
|
23
|
+
out.push('');
|
|
24
|
+
|
|
25
|
+
out.push('## Findings', '');
|
|
26
|
+
if (!r.findings.length) out.push('No findings.', '');
|
|
27
|
+
for (const [cat, info] of Object.entries(r.categories)) {
|
|
28
|
+
const list = r.findings.filter((f) => f.category === cat);
|
|
29
|
+
if (!list.length) continue;
|
|
30
|
+
out.push(`### ${info.label} (${list.length})`, '');
|
|
31
|
+
for (const f of list) {
|
|
32
|
+
out.push(`#### ${ICON[f.severity]} ${text(f.title)}`, '');
|
|
33
|
+
out.push(`**${f.severity.toUpperCase()}** · confidence ${f.confidence} · ${f.source === 'gitleaks' ? 'Gitleaks' : 'built-in'}${f.confirmedBy ? ' · confirmed by Gitleaks' : ''} · rule ${code(f.ruleId)}`, '');
|
|
34
|
+
out.push(text(f.summary), '');
|
|
35
|
+
if (f.why) out.push(`*Why it matters:* ${text(f.why)}`, '');
|
|
36
|
+
if (f.actions.length) {
|
|
37
|
+
out.push('*What to do:*', '');
|
|
38
|
+
f.actions.forEach((a, i) => out.push(`${i + 1}. ${a.replace(/\r?\n/g, ' ')}`));
|
|
39
|
+
out.push('');
|
|
40
|
+
}
|
|
41
|
+
if (f.commands.length) out.push('```sh', ...f.commands, '```', '');
|
|
42
|
+
if (f.locations.length) {
|
|
43
|
+
out.push(`*Locations${f.totalLocations > f.locations.length ? ` (first ${f.locations.length} of ${f.totalLocations})` : ''}:*`, '');
|
|
44
|
+
for (const l of f.locations.slice(0, 15)) out.push(`- ${loc(l)}`);
|
|
45
|
+
if (f.locations.length > 15) out.push(`- … ${f.totalLocations - 15} more`);
|
|
46
|
+
out.push('');
|
|
47
|
+
}
|
|
48
|
+
if (f.evidence.length) out.push('*Evidence (redacted):*', '', '```text', ...f.evidence, '```', '');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const w = r.coverage.worktree;
|
|
53
|
+
const h = r.coverage.history;
|
|
54
|
+
const g = r.coverage.gitleaks;
|
|
55
|
+
out.push('## Coverage', '');
|
|
56
|
+
out.push(`- Working tree: ${w.files} files (${w.textFiles} text) scanned, ${w.binary} binary and ${w.skippedLarge} oversized skipped, ${w.untracked} untracked files checked by name.`);
|
|
57
|
+
out.push(`- History: ${h.enabled ? `${h.commitsScanned}/${h.commits} commits on ${h.refs} refs, ${(h.patchBytes / 1048576).toFixed(1)} MB of patches${h.truncated ? ' (truncated)' : ''}` : 'not scanned'}.`);
|
|
58
|
+
out.push(`- Gitleaks: ${g?.ran ? `ran (v${g.version}), ${g.findings} matches` : g?.mode === 'off' ? 'disabled' : g?.error || 'not run'}.`);
|
|
59
|
+
out.push('', '## Limitations', '');
|
|
60
|
+
for (const l of r.limitations) out.push(`- ${text(l)}`);
|
|
61
|
+
out.push('', '---', '', '_Raw secret values are never included in Prepublic reports. Personal paths and emails are masked._', '');
|
|
62
|
+
return out.join('\n');
|
|
63
|
+
}
|