@su-sws/synthetic-web-team 0.1.2 → 0.2.1
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/AGENTS.md +79 -50
- package/README.md +22 -11
- package/package.json +3 -3
- package/packages/cli/bin/sws.mjs +80 -40
- package/packages/cli/src/acknowledged.mjs +159 -0
- package/packages/cli/src/checks.mjs +209 -20
- package/packages/cli/src/standards.mjs +26 -0
- package/packages/wizard/bin/wizard.mjs +112 -24
- package/packages/wizard/src/emit.mjs +688 -75
- package/skills/role-devops/SKILL.md +25 -2
- package/skills/role-frontend-developer/SKILL.md +9 -0
- package/skills/sws-code-review/SKILL.md +121 -0
- package/skills/sws-compliance-check/SKILL.md +16 -0
- package/skills/sws-deploy/SKILL.md +13 -0
- package/skills/sws-github/SKILL.md +65 -1
- package/skills/sws-install/SKILL.md +23 -4
- package/skills/sws-onboard/SKILL.md +7 -4
- package/standards/recipes/add-to-existing/RECIPE.md +9 -0
- package/standards/recipes/astro-ssr/RECIPE.md +4 -1
- package/standards/recipes/astro-static/RECIPE.md +31 -1
- package/standards/recipes/astro-static/acceptance.yml +38 -0
- package/standards/recipes/next-ssr/RECIPE.md +7 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Accepted risks, from .sws/acknowledged.yml, and what each one covers.
|
|
2
|
+
//
|
|
3
|
+
// AN ACKNOWLEDGEMENT COVERS WHAT IT NAMES, NOT THE WHOLE CHECK. This used to
|
|
4
|
+
// match on the check id alone and ignore `path`, though the template showed
|
|
5
|
+
// one. For minweb.no-secrets, the one blocking check, that meant accepting a
|
|
6
|
+
// single false positive in a vendored README also hid every real credential
|
|
7
|
+
// committed afterwards, anywhere in the repository. Found on a pilot, where the
|
|
8
|
+
// team noticed the risk and rewrote their fixtures instead.
|
|
9
|
+
//
|
|
10
|
+
// So a finding that reports `locations` (today, minweb.no-secrets) is accepted
|
|
11
|
+
// only location by location:
|
|
12
|
+
//
|
|
13
|
+
// path required for a blocking check. An exact file, a directory ending in
|
|
14
|
+
// `/`, or a glob (`*` within a segment, `**` across segments). A path
|
|
15
|
+
// that matches everything, such as `**`, `**/*` or `**/*.*`, counts
|
|
16
|
+
// as no path: it would bring back the check-wide acceptance this
|
|
17
|
+
// exists to stop.
|
|
18
|
+
// line optional. Narrows the entry to that line, so an edit that moves the
|
|
19
|
+
// match brings it back for a fresh look.
|
|
20
|
+
// sha256 optional. Narrows the entry to one matched value, by the full
|
|
21
|
+
// SHA-256 of that value. `sws digest <path>:<line>` prints it,
|
|
22
|
+
// locally. It is never printed in a report: a hash of a human-chosen
|
|
23
|
+
// password lets anyone holding the report check guesses offline.
|
|
24
|
+
//
|
|
25
|
+
// NOT `value`. An entry that names the matched text is ignored, loudly. The
|
|
26
|
+
// text would be copied into this tracked file, where a value found by the
|
|
27
|
+
// generic pattern no longer matches anything, so once it left its own file the
|
|
28
|
+
// only copy left would sit here unreported.
|
|
29
|
+
//
|
|
30
|
+
// Narrowing is only ever for a false positive. A real credential is rotated,
|
|
31
|
+
// not accepted.
|
|
32
|
+
//
|
|
33
|
+
// Any location no entry covers keeps the finding failing. A finding with no
|
|
34
|
+
// locations is accepted by check id as before, except that a blocking one
|
|
35
|
+
// never is: there is nothing to scope the acceptance to.
|
|
36
|
+
|
|
37
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
38
|
+
import { createHash } from 'node:crypto';
|
|
39
|
+
import { join } from 'node:path';
|
|
40
|
+
import YAML from 'yaml';
|
|
41
|
+
|
|
42
|
+
export const ACKNOWLEDGED_PATH = join('.sws', 'acknowledged.yml');
|
|
43
|
+
|
|
44
|
+
export function loadAcknowledged(root) {
|
|
45
|
+
const p = join(root, ACKNOWLEDGED_PATH);
|
|
46
|
+
if (!existsSync(p)) return [];
|
|
47
|
+
try {
|
|
48
|
+
const y = YAML.parse(readFileSync(p, 'utf8'));
|
|
49
|
+
return Array.isArray(y) ? y : (y?.accepted ?? []);
|
|
50
|
+
} catch { return []; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The full hash of a matched value, for comparing against an entry in this
|
|
54
|
+
// process. Never serialised: the CLI strips it from every location before a
|
|
55
|
+
// report is rendered.
|
|
56
|
+
export const sha256 = (s) => createHash('sha256').update(String(s)).digest('hex');
|
|
57
|
+
|
|
58
|
+
// A path that names nothing: empty once its wildcards are taken away, or one
|
|
59
|
+
// that matches file names nobody would ever choose, which is how `**/*.*` and
|
|
60
|
+
// `*.*` give themselves away. A scoped pattern (`**/*.js`, `vendor/**`,
|
|
61
|
+
// `**/README.md`, `src/`) matches neither probe.
|
|
62
|
+
const PROBES = ['sws-probe.q7x', 'sws-probe-a/sws-probe-b/sws-probe.q7x'];
|
|
63
|
+
const namesNothing = (p) => !String(p ?? '').replace(/^\.\//, '').replace(/[*?/]/g, '')
|
|
64
|
+
|| PROBES.some((probe) => pathMatches(p, probe));
|
|
65
|
+
|
|
66
|
+
// `path:line looks like a <label>`, for up to `max` locations.
|
|
67
|
+
export function describeLocations(locations, max = 5) {
|
|
68
|
+
const shown = locations.slice(0, max).map((l) =>
|
|
69
|
+
`${l.path}${l.line ? `:${l.line}` : ''}${l.label ? ` looks like a ${l.label}` : ''}`);
|
|
70
|
+
const more = locations.length - shown.length;
|
|
71
|
+
return shown.join('; ') + (more > 0 ? `; and ${more} more` : '');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// `**/` is any number of directories, including none; any other `**` is
|
|
75
|
+
// anything at all, so `test/**.json` covers `test/a.json` and `test/b/c.json`,
|
|
76
|
+
// and `vendor/**` everything under vendor/. `*` and `?` stay within one segment.
|
|
77
|
+
export function pathMatches(pattern, path) {
|
|
78
|
+
let p = String(pattern).replace(/^\.\//, '');
|
|
79
|
+
if (p.endsWith('/')) {
|
|
80
|
+
if (!/[*?]/.test(p)) return path.startsWith(p);
|
|
81
|
+
p += '**';
|
|
82
|
+
}
|
|
83
|
+
if (!/[*?]/.test(p)) return path === p;
|
|
84
|
+
const re = p.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
85
|
+
.replace(/\*\*\//g, '\u0000')
|
|
86
|
+
.replace(/\*\*/g, '\u0001')
|
|
87
|
+
.replace(/\*/g, '[^/]*')
|
|
88
|
+
.replace(/\?/g, '[^/]')
|
|
89
|
+
.replace(/\u0000/g, '(?:.*/)?')
|
|
90
|
+
.replace(/\u0001/g, '.*');
|
|
91
|
+
return new RegExp(`^${re}$`).test(path);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function covers(entry, loc) {
|
|
95
|
+
if (!pathMatches(entry.path, loc.path)) return false;
|
|
96
|
+
if (entry.line != null && Number(entry.line) !== loc.line) return false;
|
|
97
|
+
if (entry.sha256 != null && String(entry.sha256).toLowerCase() !== loc.sha256) return false;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function acceptedBy(entries, now) {
|
|
102
|
+
const by = [...new Set(entries.map((a) => a.accepted_by ?? 'unknown'))].join(', ');
|
|
103
|
+
const reasons = [...new Set(entries.map((a) => a.reason).filter(Boolean))];
|
|
104
|
+
let note = `accepted by ${by}${reasons.length === 1 ? `: ${reasons[0]}` : ''}`;
|
|
105
|
+
const overdue = entries.map((a) => a.review_by).filter((d) => d && new Date(d) < now).sort();
|
|
106
|
+
if (overdue.length) note += ` [review overdue since ${overdue[0]}]`;
|
|
107
|
+
return note;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Apply the entries for one check to its finding.
|
|
112
|
+
*
|
|
113
|
+
* Returns the finding's new `state` and `detail`, plus `ignored`: entries that
|
|
114
|
+
* were not applied because a blocking check was accepted with no path. Those
|
|
115
|
+
* are said out loud in the detail, never dropped quietly, because someone
|
|
116
|
+
* wrote them believing they worked.
|
|
117
|
+
*/
|
|
118
|
+
export function applyAcknowledgements(finding, entries, { blocking = false, now = new Date() } = {}) {
|
|
119
|
+
const everywhere = blocking ? entries.filter((a) => namesNothing(a.path)) : [];
|
|
120
|
+
const byValue = entries.filter((a) => a.value != null && !everywhere.includes(a));
|
|
121
|
+
const ignored = [...everywhere, ...byValue];
|
|
122
|
+
const usable = entries.filter((a) => !ignored.includes(a));
|
|
123
|
+
const n = (k) => `${k} acknowledgement${k > 1 ? 's' : ''} ignored`;
|
|
124
|
+
const warn = [
|
|
125
|
+
everywhere.length && ` (${n(everywhere.length)}: an entry for ${finding.id} must name a file or directory, not every path, because accepting a blocking check everywhere would hide the next real one)`,
|
|
126
|
+
byValue.length && ` (${n(byValue.length)}: \`value:\` would copy the matched text into ${ACKNOWLEDGED_PATH}; narrow by \`sha256:\` from \`sws digest <path>:<line>\` instead)`,
|
|
127
|
+
].filter(Boolean).join('');
|
|
128
|
+
|
|
129
|
+
if (finding.state !== 'fail' || !usable.length) {
|
|
130
|
+
return { state: finding.state, detail: finding.detail + warn, ignored };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const locations = finding.locations ?? [];
|
|
134
|
+
if (!locations.length) {
|
|
135
|
+
// Nothing to scope to. A non-blocking finding is accepted by id, as it always
|
|
136
|
+
// was; a blocking one stays a failure.
|
|
137
|
+
if (blocking) return { state: 'fail', detail: finding.detail + warn, ignored };
|
|
138
|
+
return { state: 'acknowledged', detail: `${finding.detail} (${acceptedBy(usable, now)})${warn}`, ignored };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const used = new Set();
|
|
142
|
+
const open = locations.filter((loc) => {
|
|
143
|
+
// A non-blocking entry without a path still covers the whole check.
|
|
144
|
+
const hit = usable.find((a) => (!a.path && !blocking) || (a.path && covers(a, loc)));
|
|
145
|
+
if (hit) used.add(hit);
|
|
146
|
+
return !hit;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (!open.length) {
|
|
150
|
+
return { state: 'acknowledged', detail: `${finding.detail} (${acceptedBy([...used], now)})${warn}`, ignored };
|
|
151
|
+
}
|
|
152
|
+
const accepted = locations.length - open.length;
|
|
153
|
+
return {
|
|
154
|
+
state: 'fail',
|
|
155
|
+
detail: describeLocations(open) + (accepted ? ` (${accepted} other match${accepted > 1 ? 'es' : ''} accepted in ${ACKNOWLEDGED_PATH})` : '') + warn,
|
|
156
|
+
locations: open,
|
|
157
|
+
ignored,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -19,6 +19,7 @@ import { RESULTS_PATH as AXE_RESULTS_PATH, SCHEMA as AXE_SCHEMA } from './axe.mj
|
|
|
19
19
|
import { RESULTS_PATH as PERF_RESULTS_PATH, SCHEMA as PERF_SCHEMA } from './perf.mjs';
|
|
20
20
|
import { RESULTS_PATH as STATE_RESULTS_PATH, SCHEMA as STATE_SCHEMA } from './states.mjs';
|
|
21
21
|
import { newestMtime } from './browser.mjs';
|
|
22
|
+
import { describeLocations, sha256 } from './acknowledged.mjs';
|
|
22
23
|
|
|
23
24
|
const read = (p) => readFileSync(p, 'utf8');
|
|
24
25
|
const readYaml = (p) => YAML.parse(read(p));
|
|
@@ -749,51 +750,169 @@ export function perf({ root, dist, html }) {
|
|
|
749
750
|
// --------------------------------------------------------------------------
|
|
750
751
|
|
|
751
752
|
const SECRET_PATTERNS = [
|
|
752
|
-
[/AKIA[0-9A-Z]{16}
|
|
753
|
-
[/gh[pousr]_[A-Za-z0-9]{36,}
|
|
754
|
-
[/sk_live_[A-Za-z0-9]{20,}
|
|
755
|
-
[/-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY
|
|
756
|
-
|
|
757
|
-
|
|
753
|
+
[/AKIA[0-9A-Z]{16}/g, 'AWS access key id'],
|
|
754
|
+
[/gh[pousr]_[A-Za-z0-9]{36,}/g, 'GitHub token'],
|
|
755
|
+
[/sk_live_[A-Za-z0-9]{20,}/g, 'Stripe live secret key'],
|
|
756
|
+
[/-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/g, 'private key'],
|
|
757
|
+
// Header, payload AND signature: two tokens that differ only in their
|
|
758
|
+
// signature are two credentials, and must not share a hash.
|
|
759
|
+
[/eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]*/g, 'JWT'],
|
|
760
|
+
// The quoted value is captured, so a placeholder can be told from a key. The
|
|
761
|
+
// optional quote after the name catches a JSON key, `"secret": "..."`, which
|
|
762
|
+
// the pattern used to miss entirely.
|
|
763
|
+
[/(?:api[_-]?key|secret|password|token)['"]?\s*[:=]\s*['"]([A-Za-z0-9!@#$%^&*_\-]{16,})['"]/gi, 'hardcoded credential'],
|
|
758
764
|
];
|
|
759
765
|
|
|
766
|
+
// Values that are plainly not credentials, so a usage example or a test fixture
|
|
767
|
+
// does not block a deploy. Both came from a pilot: `'storyblok-user-access-token'`
|
|
768
|
+
// in a vendored README, and a fixture that wrapped the word `key` in a PEM
|
|
769
|
+
// header. Deliberately narrow. Anything with digits, mixed case or no telling
|
|
770
|
+
// word still counts, because a false pass here is the one irreversible mistake.
|
|
771
|
+
// (A value in angle brackets, `'<management-token>'`, never matched at all.)
|
|
772
|
+
//
|
|
773
|
+
// The telling word must be a whole word of the phrase. Matching inside words
|
|
774
|
+
// let `monkey-horse-battery-staple` and `secretary-desk-lamp-blue`, real
|
|
775
|
+
// passphrases, through as placeholders.
|
|
776
|
+
const PLACEHOLDER_WORDS = new Set(['token', 'key', 'secret', 'password', 'passwd', 'example', 'placeholder',
|
|
777
|
+
'dummy', 'sample', 'fake', 'your', 'changeme', 'redacted']);
|
|
778
|
+
|
|
779
|
+
// (A private key's placeholder rule is in scanSecrets, which knows its block.)
|
|
780
|
+
function isPlaceholder(label, value) {
|
|
781
|
+
if (label !== 'hardcoded credential') return false;
|
|
782
|
+
if (/^(.)\1+$/.test(value)) return true; // xxxxxxxxxxxxxxxx
|
|
783
|
+
return /^[a-z]+(?:[-_][a-z]+)+$/.test(value) // storyblok-user-access-token
|
|
784
|
+
&& value.split(/[-_]/).some((w) => PLACEHOLDER_WORDS.has(w));
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Every match in one file's text, with the WHOLE credential each one stands for.
|
|
788
|
+
//
|
|
789
|
+
// The span matters twice. It is what gets hashed, so a private key is its whole
|
|
790
|
+
// block, not the header every key of that type shares, and a quoted value is
|
|
791
|
+
// all of it, not a prefix another pattern happened to match. And matches are
|
|
792
|
+
// folded only when their spans are IDENTICAL (`api_key: 'ghp_...'` is one
|
|
793
|
+
// credential). Folding any overlap let one match hide another three ways: a
|
|
794
|
+
// placeholder hid the real value after it on a line, a BEGIN...END span hid a
|
|
795
|
+
// token written between the two, and an AWS-shaped prefix hid the rest of a
|
|
796
|
+
// longer secret, so accepting the prefix accepted whatever followed it.
|
|
797
|
+
export function scanSecrets(body) {
|
|
798
|
+
const found = [];
|
|
799
|
+
for (const [re, label] of SECRET_PATTERNS) {
|
|
800
|
+
for (const m of body.matchAll(re)) {
|
|
801
|
+
let start = m.index;
|
|
802
|
+
let end = m.index + m[0].length;
|
|
803
|
+
let placeholder;
|
|
804
|
+
if (m[1] !== undefined) {
|
|
805
|
+
// The quoted value sits at the end of the match, before its quote.
|
|
806
|
+
end -= 1;
|
|
807
|
+
start = end - m[1].length;
|
|
808
|
+
} else if (label === 'private key') {
|
|
809
|
+
// Only up to the next header, so one block never takes another's footer.
|
|
810
|
+
const rest = body.slice(end);
|
|
811
|
+
const next = rest.search(/-----BEGIN [A-Z ]*PRIVATE KEY-----/);
|
|
812
|
+
const k = keyBlock(next === -1 ? rest : rest.slice(0, next));
|
|
813
|
+
end += k.end;
|
|
814
|
+
// A placeholder only when the footer directly follows too little
|
|
815
|
+
// material to be a key: the pilot's header around the word `key`.
|
|
816
|
+
// Anything else counts, failing closed: a key missing its footer is
|
|
817
|
+
// still the key, and a header with code after it is reported, as main
|
|
818
|
+
// always reported every header.
|
|
819
|
+
placeholder = k.terminated && k.material < 64;
|
|
820
|
+
}
|
|
821
|
+
const value = body.slice(start, end);
|
|
822
|
+
placeholder ??= isPlaceholder(label, value);
|
|
823
|
+
if (found.some((x) => (x.start === start && x.end === end)
|
|
824
|
+
|| (placeholder && start < x.end && x.start < end))) continue;
|
|
825
|
+
found.push({
|
|
826
|
+
start, end, label, value, placeholder,
|
|
827
|
+
line: body.slice(0, start).split('\n').length,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return found.sort((a, b) => a.start - b.start);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// What follows a private-key header, up to the next header: its key material,
|
|
835
|
+
// and its footer if that comes straight after.
|
|
836
|
+
//
|
|
837
|
+
// Key material is base64 and nothing else, unit by unit: a unit is a line, or a
|
|
838
|
+
// piece of a string literal between `\n` escapes, with the glue code puts round
|
|
839
|
+
// key material taken off (quotes, `+`, commas, a trailing `\`, indentation).
|
|
840
|
+
// The first unit that is anything else ends it, so a block can never take in
|
|
841
|
+
// code: a constant `'-----BEGIN ...'`, then a token, then `'-----END ...'`, is
|
|
842
|
+
// a header and a separate token, not one key that hides the token.
|
|
843
|
+
const KEY_GLUE = /^[\s'"`+,\\]+|[\s'"`+,\\]+$/g;
|
|
844
|
+
|
|
845
|
+
function keyBlock(rest) {
|
|
846
|
+
const units = /\\r\\n|\\n|\r?\n/g;
|
|
847
|
+
let pos = 0;
|
|
848
|
+
let end = 0;
|
|
849
|
+
let material = 0;
|
|
850
|
+
for (;;) {
|
|
851
|
+
units.lastIndex = pos;
|
|
852
|
+
const sep = units.exec(rest);
|
|
853
|
+
const raw = rest.slice(pos, sep ? sep.index : rest.length);
|
|
854
|
+
const core = raw.replace(KEY_GLUE, '');
|
|
855
|
+
const footer = core.match(/^-----END [A-Z ]*PRIVATE KEY-----/);
|
|
856
|
+
if (footer) return { end: pos + raw.indexOf(footer[0]) + footer[0].length, material, terminated: true };
|
|
857
|
+
if (core && !/^[A-Za-z0-9+/=]+$/.test(core)) break;
|
|
858
|
+
if (core) {
|
|
859
|
+
material += core.length;
|
|
860
|
+
end = pos + raw.lastIndexOf(core) + core.length;
|
|
861
|
+
}
|
|
862
|
+
if (!sep) break;
|
|
863
|
+
pos = sep.index + sep[0].length;
|
|
864
|
+
}
|
|
865
|
+
return { end, material, terminated: false };
|
|
866
|
+
}
|
|
867
|
+
|
|
760
868
|
export function secrets({ root }) {
|
|
761
869
|
let files;
|
|
762
870
|
try {
|
|
763
|
-
|
|
764
|
-
|
|
871
|
+
// -z, because without it git quotes any path with a non-ASCII byte, and a
|
|
872
|
+
// quoted path never exists on disk, so `docs/café.js` was never read.
|
|
873
|
+
files = execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8' })
|
|
874
|
+
.split('\0').filter(Boolean);
|
|
765
875
|
} catch {
|
|
766
876
|
return [dunno('minweb.no-secrets', 'not a git repository, or git unavailable; cannot enumerate tracked files')];
|
|
767
877
|
}
|
|
768
878
|
|
|
879
|
+
// EVERY match, not the first per file. Stopping at the first meant fixing one
|
|
880
|
+
// only revealed the next, one doctor run at a time. Each becomes a location,
|
|
881
|
+
// which is what an acknowledgement is scoped to. The value's hash is for
|
|
882
|
+
// matching an entry in this process only, and is stripped before any report
|
|
883
|
+
// is written: a hash of a human-chosen password is a guess-checker.
|
|
769
884
|
const SKIP = /\.(png|jpe?g|gif|webp|avif|ico|woff2?|ttf|otf|eot|pdf|zip|mp4|webm)$/i;
|
|
770
|
-
const
|
|
885
|
+
const locations = [];
|
|
886
|
+
const placeholders = [];
|
|
771
887
|
for (const f of files) {
|
|
772
888
|
if (SKIP.test(f) || f.includes('node_modules')) continue;
|
|
773
889
|
const p = join(root, f);
|
|
774
890
|
if (!existsSync(p) || statSync(p).size > 512 * 1024) continue;
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
if (m) {
|
|
779
|
-
const line = body.slice(0, m.index).split('\n').length;
|
|
780
|
-
hits.push(`${f}:${line} looks like a ${label}`);
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
891
|
+
for (const s of scanSecrets(read(p))) {
|
|
892
|
+
if (s.placeholder) placeholders.push(`${f}:${s.line}`);
|
|
893
|
+
else locations.push({ path: f, line: s.line, label: s.label, sha256: sha256(s.value) });
|
|
783
894
|
}
|
|
784
895
|
}
|
|
785
896
|
|
|
786
|
-
|
|
897
|
+
const skipped = placeholders.length
|
|
898
|
+
? ` (${placeholders.length} placeholder${placeholders.length > 1 ? 's' : ''} skipped: ${placeholders.slice(0, 3).join(', ')}${placeholders.length > 3 ? ', ...' : ''})`
|
|
899
|
+
: '';
|
|
900
|
+
if (!locations.length) {
|
|
901
|
+
return [ok('minweb.no-secrets', `${files.length} tracked files scanned, nothing found${skipped}`)];
|
|
902
|
+
}
|
|
787
903
|
|
|
788
904
|
return [{
|
|
789
905
|
id: 'minweb.no-secrets',
|
|
790
906
|
state: 'fail',
|
|
791
907
|
blocking: true,
|
|
792
|
-
|
|
908
|
+
locations,
|
|
909
|
+
detail: describeLocations(locations) + skipped,
|
|
793
910
|
fix: [
|
|
794
911
|
'ROTATE THE CREDENTIAL NOW. It is already in git history and blocking a deploy does not un-leak it.',
|
|
795
912
|
'Then remove it from history (git filter-repo or BFG), then force-push.',
|
|
796
913
|
'Then move the value into Vault or your host\'s environment settings.',
|
|
914
|
+
'Only if a match is NOT a credential: accept that one location in .sws/acknowledged.yml by its path,',
|
|
915
|
+
'narrowed with `sws digest <path>:<line>`, never the whole check.',
|
|
797
916
|
].join(' '),
|
|
798
917
|
}];
|
|
799
918
|
}
|
|
@@ -965,16 +1084,18 @@ export function workflow({ root }) {
|
|
|
965
1084
|
if (up === d) break;
|
|
966
1085
|
d = up;
|
|
967
1086
|
}
|
|
1087
|
+
const hooks = hookFinding(root);
|
|
968
1088
|
if (!dir) {
|
|
969
1089
|
return [
|
|
970
1090
|
bad('workflow.push-to-main-deploys', 'no .github/workflows directory',
|
|
971
1091
|
'Push to main should deploy. Pull requests are first-class but never required.'),
|
|
972
1092
|
dunno('workflow.report-reaches-a-reader', 'no workflows to inspect'),
|
|
1093
|
+
hooks,
|
|
973
1094
|
];
|
|
974
1095
|
}
|
|
975
1096
|
const files = readdirSync(dir).filter((f) => /\.ya?ml$/.test(f)).map((f) => join(dir, f));
|
|
976
1097
|
const all = files.map(read).join('\n---\n');
|
|
977
|
-
const out = [];
|
|
1098
|
+
const out = [hooks];
|
|
978
1099
|
|
|
979
1100
|
out.push(/on:[\s\S]{0,200}push:[\s\S]{0,120}branches:\s*\[?\s*['"]?main/.test(all)
|
|
980
1101
|
? ok('workflow.push-to-main-deploys', 'triggers on push to main')
|
|
@@ -992,6 +1113,74 @@ export function workflow({ root }) {
|
|
|
992
1113
|
return out;
|
|
993
1114
|
}
|
|
994
1115
|
|
|
1116
|
+
// Checks nag, they never gate. A problem should show up as a failed GitHub
|
|
1117
|
+
// Action that everyone can see and a person decides about, not as a refused
|
|
1118
|
+
// commit or an agent that will not stop. A pilot added both kinds of hook and
|
|
1119
|
+
// then took them all out again. So a hook that can refuse is reported, with the
|
|
1120
|
+
// suggestion to run the same check in CI. It is never removed: a team may have
|
|
1121
|
+
// chosen it, which is the same reasoning as branch protection.
|
|
1122
|
+
//
|
|
1123
|
+
// Only what the team shares counts. A developer's own .git/hooks are theirs,
|
|
1124
|
+
// and so is a .claude/settings.json that git ignores, which many teams do.
|
|
1125
|
+
const BLOCKING_AGENT_EVENTS = ['PreToolUse', 'Stop', 'SubagentStop'];
|
|
1126
|
+
|
|
1127
|
+
// The client-side git hooks whose failure refuses the operation. A README, a
|
|
1128
|
+
// helper script, or a post-* hook in .husky/ cannot stop anything.
|
|
1129
|
+
const BLOCKING_GIT_HOOKS = new Set(['applypatch-msg', 'pre-applypatch', 'pre-commit', 'pre-merge-commit',
|
|
1130
|
+
'prepare-commit-msg', 'commit-msg', 'pre-rebase', 'pre-push']);
|
|
1131
|
+
|
|
1132
|
+
function hookFinding(root) {
|
|
1133
|
+
let repo = root;
|
|
1134
|
+
for (let d = root, i = 0; i < 6; i++) {
|
|
1135
|
+
if (existsSync(join(d, '.git'))) { repo = d; break; }
|
|
1136
|
+
const up = dirname(d);
|
|
1137
|
+
if (up === d) break;
|
|
1138
|
+
d = up;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
const found = [];
|
|
1142
|
+
const husky = join(repo, '.husky');
|
|
1143
|
+
if (existsSync(husky) && statSync(husky).isDirectory()) {
|
|
1144
|
+
const named = readdirSync(husky)
|
|
1145
|
+
.filter((n) => BLOCKING_GIT_HOOKS.has(n) && statSync(join(husky, n)).isFile());
|
|
1146
|
+
if (named.length) found.push(`.husky/ (${named.join(', ')})`);
|
|
1147
|
+
}
|
|
1148
|
+
for (const n of ['lefthook.yml', 'lefthook.yaml', '.lefthook.yml', '.lefthook.yaml', '.pre-commit-config.yaml']) {
|
|
1149
|
+
if (existsSync(join(repo, n))) found.push(n);
|
|
1150
|
+
}
|
|
1151
|
+
try {
|
|
1152
|
+
const j = pkg(repo);
|
|
1153
|
+
for (const k of ['simple-git-hooks', 'pre-commit', 'pre-push']) if (j?.[k]) found.push(`package.json "${k}"`);
|
|
1154
|
+
if (j?.husky?.hooks) found.push('package.json "husky.hooks"');
|
|
1155
|
+
} catch { /* an unreadable package.json is the build check's to report */ }
|
|
1156
|
+
|
|
1157
|
+
const settings = join(repo, '.claude', 'settings.json');
|
|
1158
|
+
if (existsSync(settings) && !gitIgnores(repo, '.claude/settings.json')) {
|
|
1159
|
+
try {
|
|
1160
|
+
const events = Object.keys(JSON.parse(read(settings))?.hooks ?? {})
|
|
1161
|
+
.filter((e) => BLOCKING_AGENT_EVENTS.includes(e));
|
|
1162
|
+
if (events.length) found.push(`.claude/settings.json hooks (${events.join(', ')})`);
|
|
1163
|
+
} catch { /* not ours to parse for anything else */ }
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
return found.length
|
|
1167
|
+
? bad('workflow.no-blocking-hooks', `hooks that can refuse a commit or stop an agent: ${found.join('; ')}`,
|
|
1168
|
+
'Run the same check in CI instead, where a failure is a red check everyone can see and nothing is refused. Leave these in place unless the team agrees to move them: someone may have chosen them.')
|
|
1169
|
+
: ok('workflow.no-blocking-hooks', 'no shared git hooks or blocking agent hooks');
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// True only when git says so. Outside a repository, or with no git, the answer
|
|
1173
|
+
// is false, so the file counts as shared, which is what .claude/settings.json is
|
|
1174
|
+
// for by default.
|
|
1175
|
+
function gitIgnores(repo, rel) {
|
|
1176
|
+
try {
|
|
1177
|
+
execFileSync('git', ['check-ignore', '-q', rel], { cwd: repo, stdio: 'ignore' });
|
|
1178
|
+
return true;
|
|
1179
|
+
} catch {
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
995
1184
|
// Consent tooling, by package name and by the script hosts these products load
|
|
996
1185
|
// from. Stanford requires NO cookie banner: the Global Footer's Privacy link
|
|
997
1186
|
// carries the disclosure, and guidance actively tells units not to build one.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Where the standards are, for a project at `root`.
|
|
2
|
+
//
|
|
3
|
+
// A project vendors them (the wizard copies them in), so the local lookups come
|
|
4
|
+
// first and win. The last candidate is the copy that ships alongside the CLI,
|
|
5
|
+
// which covers `npx -p @su-sws/synthetic-web-team sws doctor` in a project that
|
|
6
|
+
// never vendored them.
|
|
7
|
+
//
|
|
8
|
+
// `.sws/standards` comes first because a root `standards/` can be the team's
|
|
9
|
+
// own folder with nothing of ours in it. So every candidate must also carry the
|
|
10
|
+
// Global Footer contract, the one file every copy of ours has, before it wins.
|
|
11
|
+
// The root is still read because an older install keeps its standards there
|
|
12
|
+
// until `add .` can move them.
|
|
13
|
+
//
|
|
14
|
+
// Its own module so it can be tested: the CLI's CI calls all pass --standards,
|
|
15
|
+
// so nothing else exercises this.
|
|
16
|
+
|
|
17
|
+
import { existsSync } from 'node:fs';
|
|
18
|
+
import { join, resolve } from 'node:path';
|
|
19
|
+
|
|
20
|
+
export function findStandards(root, { explicit = null, bundled = null } = {}) {
|
|
21
|
+
if (explicit) return resolve(explicit);
|
|
22
|
+
for (const c of [join(root, '.sws', 'standards'), join(root, 'standards'), bundled]) {
|
|
23
|
+
if (c && existsSync(join(c, 'fragments', 'global-footer.yml'))) return c;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|