@runeditrun/rer 0.2.75 → 0.2.76
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/README.md +7 -2
- package/cli/listing.mjs +20 -0
- package/cli/main.mjs +1 -0
- package/cli/parse.mjs +2 -1
- package/cli/portability-migrations.mjs +46 -0
- package/cli/portability-worker.mjs +7 -20
- package/cli/portability.mjs +5 -4
- package/cli/server-registry.mjs +43 -18
- package/cli/server-resources.mjs +38 -9
- package/global/CHANGELOG.md +8 -0
- package/global/README.md +7 -2
- package/global/launch/state.mjs +5 -4
- package/global/launch/stop.mjs +30 -8
- package/global/main.mjs +2 -1
- package/modules/job-queue/command.mjs +8 -3
- package/modules/portability/README.md +40 -11
- package/modules/portability/backfills.mjs +29 -16
- package/modules/portability/bridge.mjs +24 -29
- package/modules/portability/import.mjs +1 -2
- package/modules/portability/index.d.mts +1 -1
- package/modules/portability/ledgers.mjs +22 -0
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/release/README.md +135 -3
- package/modules/release/catalogue.mjs +6 -2
- package/modules/release/listing.mjs +64 -0
- package/modules/release/look.mjs +26 -0
- package/modules/release/previous-listing.mjs +44 -0
- package/modules/release/produce.mjs +3 -0
- package/modules/release/screenshots.mjs +51 -0
- package/modules/release/signature.mjs +3 -2
- package/modules/release/source.mjs +19 -6
- package/modules/release/statement.mjs +8 -4
- package/onboarding/process-cleanup.mjs +5 -5
- package/onboarding/process-scope.mjs +1 -1
- package/onboarding/process-table.mjs +6 -4
- package/onboarding/process-tree.mjs +4 -4
- package/onboarding/schema/json-schema.mjs +4 -1
- package/package.json +1 -1
- package/scripts/publish-check/README.md +14 -0
- package/scripts/publish-check/assignment.py +48 -0
- package/scripts/publish-check/credential_assignments.mjs +75 -0
- package/scripts/publish-check/credential_assignments.py +70 -0
- package/scripts/publish-check/credential_literals.mjs +66 -0
- package/scripts/publish-check/credential_syntax.mjs +29 -0
- package/scripts/publish-check/env_values.py +14 -1
- package/scripts/publish-check/history_scan.py +9 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { matchesGlob } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const defaultLook = Object.freeze({
|
|
5
|
+
home: ['public/brand/**', 'src/branding.json', 'public/rer-theme.css', 'public/fonts/**', 'src/site/**', '!src/site/docs/**'],
|
|
6
|
+
app: ['public/brand/**', 'src/branding.json', 'public/**/*.{css,js,mjs,html}', 'src/ui/**', 'src/**/*.css', 'src/client/**'],
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export function lookFingerprints(source) {
|
|
10
|
+
const declared = source.entries.has('rer-project.json') ? JSON.parse(source.bytes('rer-project.json')).look : undefined;
|
|
11
|
+
if (declared !== undefined && (!declared || typeof declared !== 'object' || Array.isArray(declared) || Object.keys(declared).some(key => !['home', 'app'].includes(key))))
|
|
12
|
+
throw Error('rer-project.json look must declare home and/or app glob arrays');
|
|
13
|
+
return Object.fromEntries(['home', 'app'].map(kind => {
|
|
14
|
+
const globs = declared?.[kind] ?? defaultLook[kind];
|
|
15
|
+
if (!Array.isArray(globs) || !globs.every(glob => typeof glob === 'string' && glob.replace(/^!/, '') && !/[\\\0\r\n]/.test(glob) && !glob.replace(/^!/, '').startsWith('/') && !glob.split('/').includes('..')))
|
|
16
|
+
throw Error('Look globs must be repository-relative patterns');
|
|
17
|
+
const includes = globs.filter(glob => !glob.startsWith('!')), excludes = globs.filter(glob => glob.startsWith('!')).map(glob => glob.slice(1));
|
|
18
|
+
const hash = createHash('sha256');
|
|
19
|
+
for (const path of [...source.entries.keys()].sort()) {
|
|
20
|
+
const entry = source.entries.get(path);
|
|
21
|
+
if (entry.type === 'blob' && includes.some(glob => matchesGlob(path, glob)) && !excludes.some(glob => matchesGlob(path, glob)))
|
|
22
|
+
hash.update(`${path}\0${entry.oid}\n`);
|
|
23
|
+
}
|
|
24
|
+
return [kind, `sha256:${hash.digest('hex')}`];
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { committedSource, git } from './source.mjs';
|
|
2
|
+
import { listingContent } from './listing.mjs';
|
|
3
|
+
|
|
4
|
+
const order = (a, b) => a === b ? 0 : a < b ? -1 : 1;
|
|
5
|
+
function version(value) {
|
|
6
|
+
const match = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?$/.exec(value);
|
|
7
|
+
return match ? { core: match.slice(1, 4).map(BigInt), pre: match[4]?.split('.') ?? [] } : null;
|
|
8
|
+
}
|
|
9
|
+
function compare(a, b) {
|
|
10
|
+
for (let i = 0; i < 3; i++) if (a.core[i] !== b.core[i]) return order(a.core[i], b.core[i]);
|
|
11
|
+
if (!a.pre.length || !b.pre.length) return order(Boolean(b.pre.length), Boolean(a.pre.length));
|
|
12
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
13
|
+
const x = a.pre[i], y = b.pre[i];
|
|
14
|
+
if (x === undefined || y === undefined) return order(a.pre.length, b.pre.length);
|
|
15
|
+
if (x === y) continue;
|
|
16
|
+
const nx = /^\d+$/.test(x), ny = /^\d+$/.test(y);
|
|
17
|
+
return nx && ny ? order(BigInt(x), BigInt(y)) : nx !== ny ? (nx ? -1 : 1) : order(x, y);
|
|
18
|
+
}
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Only advertised tags count. A scratch/local tag can never claim that stale
|
|
23
|
+
// pictures were public. The selected ref's own release tag is excluded.
|
|
24
|
+
export function previousListing(source, repository) {
|
|
25
|
+
if (!source.repo || !git(source.repo, 'remote').toString().split('\n').includes('origin')) return null;
|
|
26
|
+
const origin = git(source.repo, 'remote', 'get-url', 'origin').toString().trim();
|
|
27
|
+
const remote = /^(?:https:\/\/github\.com\/|git@github\.com:)/.test(origin) ? repository : origin;
|
|
28
|
+
const current = version(source.seed.version);
|
|
29
|
+
if (!current) return null;
|
|
30
|
+
const records = git(source.repo, 'ls-remote', '--tags', remote, 'refs/tags/v*').toString().trim().split('\n').filter(Boolean);
|
|
31
|
+
const refs = new Map(records.map(record => record.split('\t').reverse()));
|
|
32
|
+
const tags = [...refs].filter(([ref]) => !ref.endsWith('^{}')).map(([ref, oid]) => ({ ref, oid, commit: refs.get(ref + '^{}') ?? oid, version: version(ref.slice('refs/tags/'.length)) }))
|
|
33
|
+
.filter(tag => tag.version && compare(tag.version, current) <= 0 && tag.commit !== source.commit)
|
|
34
|
+
.sort((a, b) => compare(a.version, b.version));
|
|
35
|
+
let previous = null;
|
|
36
|
+
for (const tag of tags) {
|
|
37
|
+
// Fetch the advertised object by ID, without changing local tag refs.
|
|
38
|
+
try { git(source.repo, 'cat-file', '-e', `${tag.commit}^{commit}`); }
|
|
39
|
+
catch { git(source.repo, 'fetch', '--no-tags', '--filter=blob:none', remote, tag.oid); }
|
|
40
|
+
const prior = committedSource(source.repo, tag.commit, { hydrateFrom: remote });
|
|
41
|
+
previous = listingContent(prior, repository, previous);
|
|
42
|
+
}
|
|
43
|
+
return previous;
|
|
44
|
+
}
|
|
@@ -11,6 +11,8 @@ import { writePublishHandoff } from './publish-handoff.mjs';
|
|
|
11
11
|
import { releasePublicBase } from './public-base.mjs';
|
|
12
12
|
import { prepareTagAdoption, confirmTagAdoption, assertTagAdoption } from './tag-adoption.mjs';
|
|
13
13
|
import { placeholderMarks, placeholderMessage } from '../../cli/placeholder-mark.mjs';
|
|
14
|
+
import { listingContent } from './listing.mjs';
|
|
15
|
+
import { previousListing } from './previous-listing.mjs';
|
|
14
16
|
import { cleanupTemporary } from './cleanup.mjs';
|
|
15
17
|
import { parseTimeoutSeconds } from '../../scripts/publish-check/timeout.mjs';
|
|
16
18
|
|
|
@@ -37,6 +39,7 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
|
|
|
37
39
|
if (typeof tag === 'string' && tag !== source.tag) throw Error('Requested tag must match the committed release version');
|
|
38
40
|
const existing = git(source.repo, 'tag', '--list', source.tag).toString().trim();
|
|
39
41
|
if (existing && tag && !dryRun && (onto !== undefined || clean)) throw Error('Release tag already exists; choose a new committed version');
|
|
42
|
+
source.listingContent = listingContent(source, repository, previousListing(source, repository));
|
|
40
43
|
// Validate metadata before installs or output writes.
|
|
41
44
|
catalogue(source, project, repository, { verify: { status: 'PENDING' }, publishCheck: { status: 'PENDING' } }, preview);
|
|
42
45
|
const destination = onto !== undefined ? publicDestination(onto, repository, source.repo) : null;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { validRelativePath } from './signature.mjs';
|
|
4
|
+
|
|
5
|
+
// Inspect the WebP container and encoded image dimensions, not its extension or
|
|
6
|
+
// the author's width/height claim. No image decoder or browser is required.
|
|
7
|
+
function webpSize(bytes) {
|
|
8
|
+
if (bytes.length < 20 || bytes.toString('ascii', 0, 4) !== 'RIFF' || bytes.toString('ascii', 8, 12) !== 'WEBP' || bytes.readUInt32LE(4) + 8 !== bytes.length)
|
|
9
|
+
throw Error('Screenshot must be a complete WebP image');
|
|
10
|
+
let canvas, image;
|
|
11
|
+
for (let offset = 12; offset < bytes.length;) {
|
|
12
|
+
if (offset + 8 > bytes.length) throw Error('Invalid WebP chunk');
|
|
13
|
+
const type = bytes.toString('ascii', offset, offset + 4), size = bytes.readUInt32LE(offset + 4), start = offset + 8;
|
|
14
|
+
if (start + size + (size & 1) > bytes.length) throw Error('Invalid WebP chunk length');
|
|
15
|
+
if (type === 'VP8X' && size === 10) {
|
|
16
|
+
if (bytes[start] & 2) throw Error('Screenshot WebP must be a still image');
|
|
17
|
+
canvas = [1 + bytes.readUIntLE(start + 4, 3), 1 + bytes.readUIntLE(start + 7, 3)];
|
|
18
|
+
} else if (type === 'VP8 ' && size >= 10 && bytes.subarray(start + 3, start + 6).equals(Buffer.from([0x9d, 0x01, 0x2a]))) {
|
|
19
|
+
image = [bytes.readUInt16LE(start + 6) & 0x3fff, bytes.readUInt16LE(start + 8) & 0x3fff];
|
|
20
|
+
} else if (type === 'VP8L' && size >= 5 && bytes[start] === 0x2f) {
|
|
21
|
+
const bits = bytes.readUInt32LE(start + 1);
|
|
22
|
+
image = [(bits & 0x3fff) + 1, ((bits >>> 14) & 0x3fff) + 1];
|
|
23
|
+
}
|
|
24
|
+
offset = start + size + (size & 1);
|
|
25
|
+
}
|
|
26
|
+
if (!image || (canvas && (canvas[0] !== image[0] || canvas[1] !== image[1]))) throw Error('Invalid WebP image dimensions');
|
|
27
|
+
return image;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function screenshotSet(source, id) {
|
|
31
|
+
const screenshots = source.release?.screenshots;
|
|
32
|
+
if (screenshots === undefined) return { shots: [], assets: [], identity: null };
|
|
33
|
+
if (!Array.isArray(screenshots) || screenshots.length < 1 || screenshots.length > 5) throw Error('RELEASE.json screenshots requires 1–5 images');
|
|
34
|
+
const paths = new Set(), assets = [];
|
|
35
|
+
const shots = screenshots.map(shot => {
|
|
36
|
+
if (!validRelativePath(shot?.path) || !shot.path.endsWith('.webp') || !['alt', 'caption'].every(key => typeof shot[key] === 'string' && shot[key].trim()) || shot.width !== 1600 || shot.height !== 1000)
|
|
37
|
+
throw Error('Each screenshot needs a WebP path, alt, caption, width 1600 and height 1000');
|
|
38
|
+
const bytes = source.bytes(shot.path), [width, height] = webpSize(bytes);
|
|
39
|
+
if (width !== 1600 || height !== 1000 || bytes.length > 300 * 1024) throw Error('Screenshot WebP must be 1600x1000 and at most 300 KiB');
|
|
40
|
+
const path = `assets/seeds/${id}/${basename(shot.path)}`;
|
|
41
|
+
if (paths.has(path) || ['mark.svg', 'mark-light.svg'].includes(basename(shot.path))) throw Error('Screenshot bundle paths must be unique');
|
|
42
|
+
paths.add(path); assets.push({ path, bytes });
|
|
43
|
+
return { path, alt: shot.alt, caption: shot.caption, width, height };
|
|
44
|
+
});
|
|
45
|
+
// Byte identity plus source names distinguish a recapture at the same path
|
|
46
|
+
// from unchanged pictures; copy edits alone cannot claim a fresh capture.
|
|
47
|
+
const identities = screenshots.map((shot, index) => [shot.path, createHash('sha256').update(assets[index].bytes).digest('hex')])
|
|
48
|
+
.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
49
|
+
const identity = createHash('sha256').update(JSON.stringify(identities)).digest('hex');
|
|
50
|
+
return { shots, assets, identity };
|
|
51
|
+
}
|
|
@@ -106,7 +106,7 @@ export function compareVersion(a, b) {
|
|
|
106
106
|
return 0;
|
|
107
107
|
}
|
|
108
108
|
const requiredFiles = ['public-source.tar', 'release-receipt.json', 'publish-check.json'];
|
|
109
|
-
const filePattern = /^(public-source\.tar|release-receipt\.json|publish-check\.json|site\/[a-z0-9]+(?:-[a-z0-9]+)*\/[^/]+\/(?:release\.json|documents
|
|
109
|
+
const filePattern = /^(public-source\.tar|release-receipt\.json|publish-check\.json|site\/[a-z0-9]+(?:-[a-z0-9]+)*\/[^/]+\/(?:release\.json|documents\/.+|assets\/seeds\/[a-z0-9]+(?:-[a-z0-9]+)*\/.+))$/;
|
|
110
110
|
function safePath(path) {
|
|
111
111
|
return validRelativePath(path) && matches(path, filePattern);
|
|
112
112
|
}
|
|
@@ -131,7 +131,8 @@ export function validateStatement(s) {
|
|
|
131
131
|
if (releases.length !== 1 || releases[0].path.split('/')[2] !== s.version) refuse('STATEMENT_INVALID');
|
|
132
132
|
const prefix = releases[0].path.slice(0, -'release.json'.length);
|
|
133
133
|
if (requiredFiles.some(path => !s.files.some(f => f.path === path))
|
|
134
|
-
|| s.files.some(f => f.path.startsWith('site/') && !f.path.startsWith(prefix)
|
|
134
|
+
|| s.files.some(f => f.path.startsWith('site/') && (!f.path.startsWith(prefix)
|
|
135
|
+
|| (f.path.startsWith(prefix + 'assets/') && !f.path.startsWith(prefix + `assets/seeds/${releases[0].path.split('/')[1]}/`))))) refuse('STATEMENT_INVALID');
|
|
135
136
|
} catch (error) { sanitized(error, 'STATEMENT_INVALID'); }
|
|
136
137
|
}
|
|
137
138
|
function parseJSON(value, code) {
|
|
@@ -17,9 +17,8 @@ export function git(repo, ...args) {
|
|
|
17
17
|
} catch { throw Error('Git source operation failed'); }
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function
|
|
20
|
+
export function committedSource(repo, ref, { hydrateFrom } = {}) {
|
|
21
21
|
repo = realpathSync(repo);
|
|
22
|
-
if (git(repo, 'status', '--porcelain', '--untracked-files=all').length) throw Error('Release requires a clean source checkout');
|
|
23
22
|
const commit = git(repo, 'rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`).toString().trim();
|
|
24
23
|
const tree = git(repo, 'rev-parse', `${commit}^{tree}`).toString().trim();
|
|
25
24
|
const records = git(repo, 'ls-tree', '-r', '-z', commit).toString().split('\0').filter(Boolean);
|
|
@@ -33,15 +32,29 @@ export function inspectSource(repo, ref) {
|
|
|
33
32
|
const bytes = path => {
|
|
34
33
|
const entry = entries.get(path);
|
|
35
34
|
if (!entry || entry.type !== 'blob' || !['100644', '100755'].includes(entry.mode)) throw Error('Release input must be a committed ordinary file');
|
|
35
|
+
if (hydrateFrom) {
|
|
36
|
+
try { git(repo, 'cat-file', '-e', entry.oid); }
|
|
37
|
+
catch { git(repo, 'fetch', '--no-tags', hydrateFrom, entry.oid); }
|
|
38
|
+
}
|
|
36
39
|
return git(repo, 'cat-file', 'blob', entry.oid);
|
|
37
40
|
};
|
|
38
41
|
const seed = JSON.parse(bytes('seed.json'));
|
|
39
|
-
const
|
|
40
|
-
|
|
42
|
+
const release = entries.has('RELEASE.json') ? JSON.parse(bytes('RELEASE.json')) : {};
|
|
43
|
+
// Read this object alone: show/log may inspect unavailable parents in a
|
|
44
|
+
// shallow partial clone, even when only the timestamp was requested.
|
|
45
|
+
const committedAt = /^committer .* (\d+) [+-]\d{4}$/m.exec(git(repo, 'cat-file', 'commit', commit).toString())?.[1];
|
|
46
|
+
if (!committedAt) throw Error('Invalid Git commit timestamp');
|
|
47
|
+
const timestamp = new Date(Number(committedAt) * 1000).toISOString();
|
|
48
|
+
return { repo, commit, tree, entries, bytes, seed, release, timestamp, tag: `v${seed.version}` };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function inspectSource(repo, ref) {
|
|
52
|
+
if (git(repo, 'status', '--porcelain', '--untracked-files=all').length) throw Error('Release requires a clean source checkout');
|
|
53
|
+
const source = committedSource(repo, ref), { seed, release } = source;
|
|
54
|
+
const pkg = JSON.parse(source.bytes('package.json'));
|
|
41
55
|
if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?$/.test(seed.version) ||
|
|
42
56
|
pkg.version !== seed.version || release.version !== seed.version || !pkg.scripts?.verify) throw Error('Seed, package and release versions must agree, and verify must exist');
|
|
43
|
-
|
|
44
|
-
return { repo, commit, tree, entries, bytes, seed, release, timestamp, tag: `v${seed.version}` };
|
|
57
|
+
return source;
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
export function newOutput(repo, output) {
|
|
@@ -18,6 +18,7 @@ export async function readArtifact(directory) {
|
|
|
18
18
|
if (!pathOK(manifestPath) || !/^site\/[a-z0-9]+(?:-[a-z0-9]+)*\/(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\/release\.json$/.test(manifestPath)) refuse('PATH_UNSAFE');
|
|
19
19
|
const base = posix.dirname(manifestPath);
|
|
20
20
|
const selected = new Map();
|
|
21
|
+
const isAsset = path => path.startsWith(`${base}/assets/`);
|
|
21
22
|
const walk = (relative = '') => {
|
|
22
23
|
for (const name of readdirSync(resolve(root, relative)).sort()) {
|
|
23
24
|
const path = relative ? `${relative}/${name}` : name;
|
|
@@ -32,9 +33,9 @@ export async function readArtifact(directory) {
|
|
|
32
33
|
if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile())) refuse('PATH_UNSAFE');
|
|
33
34
|
if (stat.isFile() && stat.size > FILE_LIMIT) refuse('INPUT_TOO_LARGE');
|
|
34
35
|
if (stat.isDirectory()) {
|
|
35
|
-
if (!ancillary && path !== 'site' && path !== posix.dirname(base) && path !== base && path !== `${base}/documents` && !path.startsWith(`${base}/documents/`)) refuse('FILE_UNDECLARED');
|
|
36
|
+
if (!ancillary && path !== 'site' && path !== posix.dirname(base) && path !== base && path !== `${base}/documents` && !path.startsWith(`${base}/documents/`) && path !== `${base}/assets` && !isAsset(path)) refuse('FILE_UNDECLARED');
|
|
36
37
|
walk(path);
|
|
37
|
-
} else if (required.includes(path) || path === manifestPath || path.startsWith(`${base}/documents/`)) {
|
|
38
|
+
} else if (required.includes(path) || path === manifestPath || path.startsWith(`${base}/documents/`) || isAsset(path)) {
|
|
38
39
|
selected.set(path, stat.size);
|
|
39
40
|
if (selected.size > 256) refuse('INPUT_TOO_LARGE');
|
|
40
41
|
} else if (!ancillary && !['PUBLISH.md', 'site/registry.json', SIGNATURE_FILE].includes(path)) refuse('FILE_UNDECLARED');
|
|
@@ -62,14 +63,17 @@ export async function readArtifact(directory) {
|
|
|
62
63
|
if (!Array.isArray(manifest.artifacts)) refuse('STATEMENT_INVALID');
|
|
63
64
|
const declared = new Set();
|
|
64
65
|
for (const artifact of manifest.artifacts) {
|
|
65
|
-
if (!pathOK(artifact?.path) || !artifact.path.startsWith('documents/')) refuse('PATH_UNSAFE');
|
|
66
|
+
if (!pathOK(artifact?.path) || !(artifact.path.startsWith('documents/') || artifact.path.startsWith(`assets/seeds/${manifest.listing.id}/`))) refuse('PATH_UNSAFE');
|
|
66
67
|
const path = `${base}/${artifact.path}`;
|
|
67
68
|
if (declared.has(path)) refuse('STATEMENT_INVALID');
|
|
68
69
|
declared.add(path);
|
|
69
70
|
if (!files.has(path)) refuse('FILE_MISSING');
|
|
70
71
|
match(path, artifact.sha256);
|
|
71
72
|
}
|
|
72
|
-
for (const path of files.keys()) if (path.startsWith(`${base}/documents/`) && !declared.has(path)) refuse('FILE_UNDECLARED');
|
|
73
|
+
for (const path of files.keys()) if ((path.startsWith(`${base}/documents/`) || isAsset(path)) && !declared.has(path)) refuse('FILE_UNDECLARED');
|
|
74
|
+
for (const path of [manifest.listing.brand?.mark, manifest.listing.brand?.markLight, ...(manifest.listing.shots ?? []).map(shot => typeof shot === 'string' ? shot : shot.path)].filter(Boolean)) {
|
|
75
|
+
if (!pathOK(path) || !declared.has(`${base}/${path}`)) refuse('FILE_MISSING');
|
|
76
|
+
}
|
|
73
77
|
return { root, receipt, subject, files, entries };
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises'
|
|
2
|
-
import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth,
|
|
2
|
+
import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth, validPid } from './process-table.mjs'
|
|
3
3
|
import { readOwnedTree } from './process-tree.mjs'
|
|
4
4
|
|
|
5
5
|
const graceMs = 1000
|
|
@@ -8,7 +8,7 @@ const cleanupMs = 30000
|
|
|
8
8
|
const pollMs = process.platform === 'darwin' ? 5 : 25
|
|
9
9
|
const isZombie = (member) => member.state.startsWith('Z')
|
|
10
10
|
const isStopped = (member) => /^[Tt]/.test(member.state)
|
|
11
|
-
const key = (member) => `${member.pid}:${member.birth}
|
|
11
|
+
const key = (member) => `${member.pid}:${member.birth}`
|
|
12
12
|
const isLeaf = (member, group) => !group.some((other) => other.ppid === member.pid)
|
|
13
13
|
|
|
14
14
|
// Ask every owned process to shut down gracefully, including supervisors that
|
|
@@ -24,7 +24,7 @@ export async function stopOwnedGroup(child, signal, ownership) {
|
|
|
24
24
|
const inspect = async (timeout) => {
|
|
25
25
|
const current = await readOwnedTree(child, ownership, timeout)
|
|
26
26
|
// Retain departed group leaders as provenance, not as signal targets.
|
|
27
|
-
for (const member of current) if (!ownership.some(saved =>
|
|
27
|
+
for (const member of current) if (!ownership.some(saved => sameBirth(saved, member))) ownership.push(member)
|
|
28
28
|
return current
|
|
29
29
|
}
|
|
30
30
|
let group
|
|
@@ -45,7 +45,7 @@ export async function stopOwnedGroup(child, signal, ownership) {
|
|
|
45
45
|
// signal. Never send a negative/group signal that can kill parents first.
|
|
46
46
|
const current = requireLeaf ? await readProcessTable(inspectionMs) : []
|
|
47
47
|
const target = await readProcessIdentity(member.pid, inspectionMs)
|
|
48
|
-
if (!
|
|
48
|
+
if (!sameBirth(member, target) || isZombie(target)) return false
|
|
49
49
|
if (requireLeaf && !isLeaf(target, current)) return false
|
|
50
50
|
if (name === 'SIGKILL' && !isStopped(target)) return false
|
|
51
51
|
if (requireLeaf && target.pid === pgid && current.some(other => other.pid !== pgid
|
|
@@ -66,7 +66,7 @@ export async function stopOwnedGroup(child, signal, ownership) {
|
|
|
66
66
|
const leader = ownership.find(member => member.pid === pgid)
|
|
67
67
|
if (leader && child.exitCode == null && child.signalCode == null) {
|
|
68
68
|
const live = await readProcessIdentity(pgid, inspectionMs)
|
|
69
|
-
if (
|
|
69
|
+
if (sameBirth(leader, live) && live.ppid === process.pid && !isZombie(live)) {
|
|
70
70
|
try { process.kill(pgid, signal); signalled.set(key(live), Date.now()) }
|
|
71
71
|
catch (error) { if (error.code !== 'ESRCH') throw new Error(`Could not send ${signal} to owned process ${pgid}.`) }
|
|
72
72
|
}
|
|
@@ -90,7 +90,7 @@ export async function scopedProcesses(scope, table, timeout = inspectionMs, prev
|
|
|
90
90
|
}
|
|
91
91
|
// A recycled PID must not transfer a token reading to its successor. PGID may
|
|
92
92
|
// legitimately change, so follow the same birth identity across that change.
|
|
93
|
-
// The caller rechecks each match's
|
|
93
|
+
// The caller rechecks each match's PID/start identity, including across exec.
|
|
94
94
|
return matches
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -119,10 +119,13 @@ export async function readProcessIdentity(pid, timeout = inspectionMs) {
|
|
|
119
119
|
return withinBound(timeout, (remaining) => psIdentity(pid, remaining))
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// macOS ps comm is read from the process's own argv, which process.title
|
|
123
|
+
// rewrites (the job supervisor retitles itself after launch). ucomm is the
|
|
124
|
+
// kernel's executable name: set only by exec, so it survives a retitle.
|
|
122
125
|
async function psIdentity(pid, timeout) {
|
|
123
126
|
let stdout
|
|
124
127
|
try {
|
|
125
|
-
({ stdout } = await execute('/bin/ps', ['-p', String(pid), '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=', '-o', '
|
|
128
|
+
({ stdout } = await execute('/bin/ps', ['-p', String(pid), '-o', 'pid=', '-o', 'ppid=', '-o', 'pgid=', '-o', 'uid=', '-o', 'stat=', '-o', 'lstart=', '-o', 'ucomm='],
|
|
126
129
|
{ env: { ...process.env, LC_ALL: 'C', TZ: 'UTC' }, timeout, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024 }))
|
|
127
130
|
} catch (error) { if (error.code === 1 && !error.stdout?.trim()) return; throw transient('Could not inspect process identity.') }
|
|
128
131
|
const match = stdout.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.{24})\s+(.+?)\s*$/)
|
|
@@ -150,7 +153,6 @@ export async function readProcessTable(timeout = inspectionMs, pgid, read = proc
|
|
|
150
153
|
}, extension)
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
// Custody follows a process lifetime: exec changes its executable name without
|
|
157
|
+
// changing its PID or start time. Names are metadata, never lifetime identity.
|
|
153
158
|
export const sameBirth = (left, right) => validPid(left?.pid) && left.pid === right?.pid && left.birth === right?.birth
|
|
154
|
-
|
|
155
|
-
export const sameProcess = (left, right) => validPid(left?.pid) && left?.pid === right?.pid
|
|
156
|
-
&& left?.birth === right?.birth && left?.command === right?.command
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { scopedProcesses } from './process-scope.mjs'
|
|
2
|
-
import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth,
|
|
2
|
+
import { inspectionMs, readProcessIdentity, readProcessTable, sameBirth, validPid } from './process-table.mjs'
|
|
3
3
|
|
|
4
|
-
// Retain PID/start
|
|
4
|
+
// Retain PID/start identities across exec and after close. An inherited marker
|
|
5
5
|
// recovers descendants after reparenting; group membership and cwd never grant
|
|
6
6
|
// ownership. Inspect executable identity only for actual custody candidates.
|
|
7
7
|
export async function readOwnedTree(child, previous = [], timeout = inspectionMs, scope = previous.scope) {
|
|
@@ -9,12 +9,12 @@ export async function readOwnedTree(child, previous = [], timeout = inspectionMs
|
|
|
9
9
|
const table = await readProcessTable(timeout)
|
|
10
10
|
const candidates = table.filter(member => previous.some(saved => sameBirth(member, saved)))
|
|
11
11
|
let owned = (await Promise.all(candidates.map(member => readProcessIdentity(member.pid, timeout))))
|
|
12
|
-
.filter(member => member && previous.some(saved =>
|
|
12
|
+
.filter(member => member && previous.some(saved => sameBirth(member, saved)))
|
|
13
13
|
if (scope) {
|
|
14
14
|
for (const member of await scopedProcesses(scope, table, timeout, previous)) {
|
|
15
15
|
if (owned.some(saved => sameBirth(saved, member))) continue
|
|
16
16
|
const live = await readProcessIdentity(member.pid, timeout)
|
|
17
|
-
if (sameBirth(member, live) && !owned.some(saved =>
|
|
17
|
+
if (sameBirth(member, live) && !owned.some(saved => sameBirth(saved, live))) owned.push(live)
|
|
18
18
|
}
|
|
19
19
|
} else if (!previous.length && child.exitCode == null && child.signalCode == null) {
|
|
20
20
|
const leader = await readProcessIdentity(child.pid, timeout)
|
|
@@ -23,7 +23,7 @@ function isDeepStrictEqual(left, right) {
|
|
|
23
23
|
const SUPPORTED = new Set([
|
|
24
24
|
'$schema', '$id', '$ref', '$defs', 'title', 'description',
|
|
25
25
|
'type', 'enum', 'const', 'required', 'properties', 'additionalProperties',
|
|
26
|
-
'propertyNames', 'items', 'minItems', 'minLength', 'pattern', 'format',
|
|
26
|
+
'propertyNames', 'items', 'minItems', 'maxItems', 'minLength', 'pattern', 'format',
|
|
27
27
|
'allOf', 'if', 'then', 'uniqueItems'
|
|
28
28
|
]);
|
|
29
29
|
|
|
@@ -181,6 +181,9 @@ export function validate(schema, data, { root = schema, path = '$', label = '' }
|
|
|
181
181
|
if (schema.minItems !== undefined && data.length < schema.minItems) {
|
|
182
182
|
fail(`needs at least ${schema.minItems} item(s)`);
|
|
183
183
|
}
|
|
184
|
+
if (schema.maxItems !== undefined && data.length > schema.maxItems) {
|
|
185
|
+
fail(`needs at most ${schema.maxItems} item(s)`);
|
|
186
|
+
}
|
|
184
187
|
if (schema.items) {
|
|
185
188
|
data.forEach((item, index) => {
|
|
186
189
|
errors.push(...validate(schema.items, item, { root, path: `${path}[${index}]` }));
|
package/package.json
CHANGED
|
@@ -27,6 +27,20 @@ Hexadecimal credential assignments also use a Gitleaks rule without generic
|
|
|
27
27
|
entropy or English stopword filters. Both assignment rules go through the same
|
|
28
28
|
location-bound Source/module identity classification; provider and environment findings
|
|
29
29
|
remain independent.
|
|
30
|
+
`assignment.py` narrows only comma-separated pairs: the complete left token
|
|
31
|
+
must contain only letters, digits, underscores or hyphens. Gitleaks still
|
|
32
|
+
requires a secret-shaped right value, using its inherited entropy/length policy
|
|
33
|
+
or the hex rule. Native locations bind the check to the full key in files and
|
|
34
|
+
messages, so a filename or path's key-like suffix cannot become a key. Other
|
|
35
|
+
assignment operators retain their existing grammar.
|
|
36
|
+
|
|
37
|
+
`env_values.py` only hashes decoded dotenv values that have at least 16
|
|
38
|
+
characters, have Shannon entropy greater than 3.5 bits per character (the pinned
|
|
39
|
+
Gitleaks generic-api-key threshold), or start with a known token prefix:
|
|
40
|
+
`sk_`, `sk-`, `pk_live`, `ghp_`, `github_pat_`, `xox`, `AKIA`, `SG.`, or `eyJ`.
|
|
41
|
+
Prefix matching is case-sensitive. Ordinary short words, statuses and short
|
|
42
|
+
numeric IDs therefore do not become environment matches. Eligible values are still
|
|
43
|
+
compared only through in-memory digests and cannot be waived.
|
|
30
44
|
`tree_scan.py` applies the kept text and licence policy. `history_scan.py`
|
|
31
45
|
assigns release, working-tree and historical scopes. Inspection returns each
|
|
32
46
|
text's repository references instead of resolving them; `history_scan.py`
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Require a complete identifier key for comma-separated credential pairs."""
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from hit_location import match_spans
|
|
5
|
+
|
|
6
|
+
IDENTIFIER = re.compile(br'[A-Za-z0-9_-]+\Z')
|
|
7
|
+
COMMA = re.compile(br''',[\x60'"\s=]{0,5}\Z''')
|
|
8
|
+
BOUNDARIES = b" \t\r\n\v\f\"'`[]{}(),;:=<>|?"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def identifier_before(data, end):
|
|
12
|
+
left = data[:end].rstrip()
|
|
13
|
+
if not left:
|
|
14
|
+
return False
|
|
15
|
+
end = len(left)
|
|
16
|
+
if left[-1] in b"\"'":
|
|
17
|
+
quote = left[-1]
|
|
18
|
+
start = end - 2
|
|
19
|
+
while start >= 0:
|
|
20
|
+
if left[start] == quote:
|
|
21
|
+
previous = start - 1
|
|
22
|
+
while previous >= 0 and left[previous] == ord('\\'):
|
|
23
|
+
previous -= 1
|
|
24
|
+
if (start - previous - 1) % 2 == 0:
|
|
25
|
+
return bool(IDENTIFIER.fullmatch(left[start + 1:end - 1]))
|
|
26
|
+
start -= 1
|
|
27
|
+
return False
|
|
28
|
+
start = end
|
|
29
|
+
while start and left[start - 1] not in BOUNDARIES:
|
|
30
|
+
start -= 1
|
|
31
|
+
return bool(IDENTIFIER.fullmatch(left[start:end]))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def is_assignment(data, hit):
|
|
35
|
+
# Gitleaks alone decides whether the right value meets its entropy/length
|
|
36
|
+
# policy (or the hex rule). Every other assignment operator is unchanged.
|
|
37
|
+
if hit.get('RuleID') not in ('generic-api-key', 'hex-api-key'):
|
|
38
|
+
return True
|
|
39
|
+
match = hit.get('Match', '').encode('utf-8')
|
|
40
|
+
secret = hit.get('Secret', '').encode('utf-8')
|
|
41
|
+
value = match.rfind(secret) if secret else -1
|
|
42
|
+
comma = COMMA.search(match[:value]) if value >= 0 else None
|
|
43
|
+
if comma is None:
|
|
44
|
+
return True
|
|
45
|
+
spans = match_spans(data, hit)
|
|
46
|
+
# Keep findings whose exact native location cannot be resolved. Reading the
|
|
47
|
+
# whole left token also rejects a key-like suffix inside a path or string.
|
|
48
|
+
return not spans or any(identifier_before(data, start + comma.start()) for start, _ in spans)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** SEC-3 credential assignment: literal syntax, entropy and fixture/reference semantics. */
|
|
2
|
+
import {codeSource, typeDeclarations} from './credential_syntax.mjs';
|
|
3
|
+
import {carriesCredential, isPlaceholder, cssLiteral} from './credential_literals.mjs';
|
|
4
|
+
|
|
5
|
+
function shannonEntropy(value) {
|
|
6
|
+
const counts = new Map();
|
|
7
|
+
for (const char of value) counts.set(char, (counts.get(char) ?? 0) + 1);
|
|
8
|
+
const length = [...value].length;
|
|
9
|
+
let entropy = 0;
|
|
10
|
+
for (const count of counts.values()) { const p = count / length; entropy -= p * Math.log2(p); }
|
|
11
|
+
return entropy;
|
|
12
|
+
}
|
|
13
|
+
// Bounded name parts keep matching linear on long lines (no unbounded backtracking before the keyword).
|
|
14
|
+
const assignment=/(?<![A-Za-z0-9_.$-])([A-Za-z0-9_.$-]{0,48}(?:secret|token|passw(?:or)?d|api[_-]?key|private[_-]?key)[A-Za-z0-9_]{0,48})["'\]]?[ \t]{0,8}(?::=|:|=)[ \t\r\n]{0,8}(["'`])([^"'`\s]{16,512})\2/gi
|
|
15
|
+
// Unquoted source identifiers and expressions are references, never literal credential values.
|
|
16
|
+
const numberAssignment=/(?<![A-Za-z0-9_.$-])([A-Za-z0-9_.$-]{0,48}(?:secret|token|passw(?:or)?d|api[_-]?key|private[_-]?key)[A-Za-z0-9_]{0,48})[ \t]{0,8}(?::=|:|=)[ \t]{0,8}([+-]?(?:0x[\da-f]{16,512}|\d{16,512}))(?![\w.$])/gi
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function parameterType(text,match){
|
|
20
|
+
// A colon directly after a parameter name describes its type. Defaults use '=' and still scan.
|
|
21
|
+
const afterName=match[0].slice(match[1].length)
|
|
22
|
+
return /^[ \t]*:/.test(afterName)&&/(?:^|[,(])[ \t\r\n]*$/.test(text.slice(Math.max(0,match.index -256),match.index))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const envAssignment=/^[ \t]{0,8}(?:export[ \t]+)?([A-Za-z0-9_]{0,48}(?:SECRET|TOKEN|PASSW(?:OR)?D|API_?KEY|PRIVATE_?KEY)[A-Za-z0-9_]{0,48})[ \t]*=[ \t]*([^\s"'`#]{16,512})[ \t]*$/gim
|
|
26
|
+
|
|
27
|
+
/** SEC-3: names that look like credentials assigned a literal of at least 16 characters with entropy ≥ 3.5 bits, other than CSS assigned to a token name (cssLiteral). */
|
|
28
|
+
function findCredentialAssignments(text,options={}) {
|
|
29
|
+
const found=[],types=options.code===false?[]:typeDeclarations(text)
|
|
30
|
+
const consider=(name,value,index)=>{
|
|
31
|
+
// Theme and design tokens are named token; CSS is never a secret's, password's or key's value.
|
|
32
|
+
if(types.some(({start,end})=>index>=start&&index<end)||shannonEntropy(value)<3.5||!/secret|passw|key/i.test(name)&&cssLiteral(value))return
|
|
33
|
+
if(/^(process\.env|import\.meta\.env|env\.|c\.env)/.test(value))return
|
|
34
|
+
found.push({name,value,index,placeholder:isPlaceholder(value)})
|
|
35
|
+
}
|
|
36
|
+
for(const match of text.matchAll(assignment))if(!parameterType(text,match))consider(match[1],match[3],match.index +match[0].lastIndexOf(match[3]))
|
|
37
|
+
for(const pattern of [numberAssignment,...(options.code===false?[envAssignment]:[])])for(const match of text.matchAll(pattern))if(!parameterType(text,match))consider(match[1],match[2],match.index +match[0].lastIndexOf(match[2]))
|
|
38
|
+
return found
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A URL or module/route path is a reference, not the credential value itself.
|
|
42
|
+
// Known credential formats are still scanned throughout those literals.
|
|
43
|
+
function referenceLiteral(value){
|
|
44
|
+
if(/^(?:\.{1,2}\/|\/)[A-Za-z0-9_./{}:-]+$/.test(value))return true
|
|
45
|
+
try{const url=new URL(value);return ['https:','http:'].includes(url.protocol)&&!url.username&&!url.password&&!url.search&&!url.hash}catch{return false}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// In call('/route?token='+encodeURIComponent(value)), the quote closes the URL.
|
|
49
|
+
// The assignment heuristic otherwise consumes the following JS expression as a quoted value.
|
|
50
|
+
function queryConcatenation(text,match){
|
|
51
|
+
return match.value.startsWith('+')&&/[?&][A-Za-z0-9_.-]+=["'`]$/.test(text.slice(Math.max(0,match.index-128),match.index))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/** The hosted rule scans every file; its extension determines identifier/type syntax only. */
|
|
56
|
+
export function sourceCredentialFindings(text, path) {
|
|
57
|
+
return findCredentialAssignments(text, {code: codeSource(path)})
|
|
58
|
+
.filter(match => !match.placeholder && !queryConcatenation(text, match) &&
|
|
59
|
+
(carriesCredential(match.value) || !/^synthetic[-_]/i.test(match.value) && !referenceLiteral(match.value)))
|
|
60
|
+
.map(match => ({index: match.index, rule: 'SEC-3 credential assignment'}))
|
|
61
|
+
.sort((a, b) => a.index - b.index);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// A single worker serves the Python scanner's files without a process per blob.
|
|
65
|
+
// The protocol returns locations only, including on malformed input.
|
|
66
|
+
if (process.argv[1] === import.meta.filename) {
|
|
67
|
+
const {createInterface} = await import('node:readline');
|
|
68
|
+
for await (const input of createInterface({input: process.stdin, crlfDelay: Infinity})) {
|
|
69
|
+
try {
|
|
70
|
+
const {text, path} = JSON.parse(input);
|
|
71
|
+
const findings = sourceCredentialFindings(text, path).map(({index}) => ({line: text.slice(0, index).split('\n').length}));
|
|
72
|
+
process.stdout.write(JSON.stringify(findings) + '\n');
|
|
73
|
+
} catch { process.stdout.write('null\n'); }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Register SEC-3 with text inspection and value-free, line-aware reports."""
|
|
2
|
+
import atexit
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import subprocess
|
|
7
|
+
from git_history import InspectionError
|
|
8
|
+
from report import Findings as PublicationFindings
|
|
9
|
+
from tree_scan import text_rules as publication_text_rules
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class AssignmentFinding:
|
|
14
|
+
line: int
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AssignmentScanner:
|
|
18
|
+
def __init__(self):
|
|
19
|
+
self.worker = None
|
|
20
|
+
atexit.register(self.close)
|
|
21
|
+
|
|
22
|
+
def findings(self, data, path):
|
|
23
|
+
try:
|
|
24
|
+
if self.worker is None:
|
|
25
|
+
self.worker = subprocess.Popen(
|
|
26
|
+
['node', str(Path(__file__).with_suffix('.mjs'))],
|
|
27
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
|
|
28
|
+
text=True, encoding='utf-8')
|
|
29
|
+
self.worker.stdin.write(json.dumps(dict(text=data.decode('utf-8', 'replace'), path=path)) + '\n')
|
|
30
|
+
self.worker.stdin.flush()
|
|
31
|
+
result = json.loads(self.worker.stdout.readline())
|
|
32
|
+
if not isinstance(result, list) or any(not isinstance(hit.get('line'), int) or hit['line'] < 1 for hit in result):
|
|
33
|
+
raise ValueError('invalid SEC-3 response')
|
|
34
|
+
return {AssignmentFinding(hit['line']) for hit in result}
|
|
35
|
+
except (OSError, ValueError, AttributeError, TypeError):
|
|
36
|
+
raise InspectionError('scan.credential-assignment-incomplete') from None
|
|
37
|
+
|
|
38
|
+
def close(self):
|
|
39
|
+
if self.worker is not None:
|
|
40
|
+
self.worker.stdin.close()
|
|
41
|
+
self.worker.wait()
|
|
42
|
+
self.worker.stdout.close()
|
|
43
|
+
self.worker = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
scanner = AssignmentScanner()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def text_rules(data, path, config, env_hashes, **message_options):
|
|
50
|
+
rules, provenance, references = publication_text_rules(data, path, config, env_hashes,
|
|
51
|
+
**message_options)
|
|
52
|
+
# History explicitly supplies True for commits and False for annotated tags.
|
|
53
|
+
# File calls omit that flag, even when the file has a metadata-looking name.
|
|
54
|
+
if 'commit_message' not in message_options:
|
|
55
|
+
rules.update(scanner.findings(data, path))
|
|
56
|
+
return rules, provenance, references
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class Findings(PublicationFindings):
|
|
60
|
+
def add(self, rule, path, commit=None, oid=None, scope='newly-public', bucket=None, scanner_rule=None):
|
|
61
|
+
if not isinstance(rule, AssignmentFinding):
|
|
62
|
+
return super().add(rule, path, commit, oid, scope, bucket, scanner_rule)
|
|
63
|
+
bucket = bucket or ('preExisting' if scope == 'pre-existing' else 'findings')
|
|
64
|
+
# The internal discriminator keeps separate lines separate while using
|
|
65
|
+
# the existing history/scope deduplication and path redaction.
|
|
66
|
+
discriminator = 'SEC-3:' + str(rule.line)
|
|
67
|
+
super().add('SEC-3', path, commit, oid, scope, bucket, discriminator)
|
|
68
|
+
item = self.seen[bucket, 'SEC-3', path, oid, discriminator]
|
|
69
|
+
item['line'] = rule.line
|
|
70
|
+
item.pop('scannerRule', None)
|