@sonordev/contracts 2.26.0 → 2.28.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/README.md +82 -1
- package/dist/booking-intake-normalize.d.ts +152 -0
- package/dist/booking-intake.d.ts +68 -0
- package/dist/booking-intake.js +221 -0
- package/dist/booking-intake.mjs +203 -0
- package/dist/quote-screen.d.ts +29 -0
- package/dist/quote-screen.js +194 -0
- package/dist/quote-screen.mjs +190 -0
- package/dist/quote-screen.vectors.d.ts +23 -0
- package/dist/resonance-confirmation.d.ts +238 -0
- package/dist/resonance-confirmation.js +163 -0
- package/dist/resonance-confirmation.mjs +131 -0
- package/dist/resonance.d.ts +364 -5
- package/dist/resonance.js +194 -13
- package/dist/resonance.mjs +179 -14
- package/dist/schema-placeholders.d.ts +2 -2
- package/dist/seo-pages.js +3 -3
- package/dist/seo-pages.mjs +3 -3
- package/dist/sites-normalize.d.ts +7 -0
- package/dist/sites.d.ts +1 -3
- package/dist/sites.js +3 -3
- package/dist/sites.mjs +3 -3
- package/package.json +17 -2
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// src/contracts/sites-normalize.ts
|
|
2
|
+
function normalizeSiteHost(site) {
|
|
3
|
+
if (!site || typeof site !== "string") return null;
|
|
4
|
+
let s = site.trim().toLowerCase();
|
|
5
|
+
if (!s) return null;
|
|
6
|
+
s = s.replace(/^https?:\/\//, "");
|
|
7
|
+
const slash = s.indexOf("/");
|
|
8
|
+
if (slash >= 0) s = s.slice(0, slash);
|
|
9
|
+
const colon = s.indexOf(":");
|
|
10
|
+
if (colon >= 0) s = s.slice(0, colon);
|
|
11
|
+
s = s.replace(/\.+$/, "");
|
|
12
|
+
return s || null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/contracts/public-url-host.ts
|
|
16
|
+
function isPrivateIpv4(a, b) {
|
|
17
|
+
return a === 127 || a === 10 || a === 0 || a === 192 && b === 168 || a === 172 && b >= 16 && b <= 31 || a === 169 && b === 254 || a === 100 && b >= 64 && b <= 127 || a >= 224;
|
|
18
|
+
}
|
|
19
|
+
function ipv6Words(host) {
|
|
20
|
+
if (!host.includes(":") || !/^[a-f\d:.]+$/.test(host)) return null;
|
|
21
|
+
let canonical;
|
|
22
|
+
try {
|
|
23
|
+
canonical = new URL(`http://[${host}]/`).hostname.slice(1, -1);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const sides = canonical.split("::");
|
|
28
|
+
const left = sides[0] ? sides[0].split(":") : [];
|
|
29
|
+
const right = sides.length > 1 && sides[1] ? sides[1].split(":") : [];
|
|
30
|
+
return [...left, ...Array(sides.length > 1 ? 8 - left.length - right.length : 0).fill("0"), ...right].map((word) => parseInt(word, 16));
|
|
31
|
+
}
|
|
32
|
+
function isBlockedPublicUrlHost(rawHost) {
|
|
33
|
+
const host = rawHost.toLowerCase().replace(/^\[|\]$/g, "");
|
|
34
|
+
const blockedName = host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal");
|
|
35
|
+
if (host.includes(":") && host.includes("%")) return true;
|
|
36
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
37
|
+
const blockedIp = !!ipv4 && isPrivateIpv4(Number(ipv4[1]), Number(ipv4[2]));
|
|
38
|
+
const words = ipv6Words(host);
|
|
39
|
+
const blockedIpv6 = !!words && // Unspecified/loopback, unique-local, link-local, deprecated site-local
|
|
40
|
+
// and multicast destinations aren't public logo/webhook endpoints.
|
|
41
|
+
(words.every((word) => word === 0) || words.slice(0, 7).every((word) => word === 0) && words[7] === 1 || (words[0] & 65024) === 64512 || (words[0] & 65472) === 65152 || (words[0] & 65472) === 65216 || (words[0] & 65280) === 65280 || // IPv4-mapped and older IPv4-compatible forms carry an IPv4 destination.
|
|
42
|
+
words.slice(0, 5).every((word) => word === 0) && [0, 65535].includes(words[5]) && isPrivateIpv4(words[6] >> 8, words[6] & 255));
|
|
43
|
+
return blockedName || blockedIp || blockedIpv6;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/contracts/booking-intake-normalize.ts
|
|
47
|
+
var BOOKING_BUSINESS_STEPS = ["off", "optional", "required"];
|
|
48
|
+
function parseBookingBusinessStep(value) {
|
|
49
|
+
return BOOKING_BUSINESS_STEPS.includes(value) ? value : "off";
|
|
50
|
+
}
|
|
51
|
+
function bookingAsksBusiness(step) {
|
|
52
|
+
return parseBookingBusinessStep(step) !== "off";
|
|
53
|
+
}
|
|
54
|
+
var BOOKING_GUEST_BUSINESS_FIELDS = { company: "company", website: "website", noWebsite: "noWebsite" };
|
|
55
|
+
var BOOKING_COMPANY_MAX = 120;
|
|
56
|
+
var BOOKING_WEBSITE_INPUT_MAX = 300;
|
|
57
|
+
var BOOKING_WEBSITE_URL_MAX = 300;
|
|
58
|
+
var NAME_WHITESPACE = /[\t\n\v\f\r \u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]+/gu;
|
|
59
|
+
var NAME_REMOVED = /[\p{Cc}\p{Cf}\p{Cs}]/gu;
|
|
60
|
+
var characters = (text) => Array.from(text).length;
|
|
61
|
+
function normalizeBookingCompany(value) {
|
|
62
|
+
if (typeof value !== "string") return null;
|
|
63
|
+
const text = value.replace(NAME_WHITESPACE, " ").replace(NAME_REMOVED, "").replace(/ {2,}/g, " ").trim();
|
|
64
|
+
return text || null;
|
|
65
|
+
}
|
|
66
|
+
var INVALID = { ok: false, reason: "invalid" };
|
|
67
|
+
var TOO_LONG = { ok: false, reason: "too_long" };
|
|
68
|
+
var PUBLIC_TLD = /^(?:[a-z]{2,63}|xn--[a-z0-9-]{1,59})$/;
|
|
69
|
+
var HOST_LABEL = /^[a-z0-9_-]{1,63}$/;
|
|
70
|
+
function normalizeGuestWebsite(value) {
|
|
71
|
+
if (value === null || value === void 0) return null;
|
|
72
|
+
if (typeof value !== "string") return INVALID;
|
|
73
|
+
const text = value.trim();
|
|
74
|
+
if (!text) return null;
|
|
75
|
+
if (characters(text) > BOOKING_WEBSITE_INPUT_MAX) return TOO_LONG;
|
|
76
|
+
if (/[\s\p{Cc}\p{Cf}\\]/u.test(text)) return INVALID;
|
|
77
|
+
let candidate;
|
|
78
|
+
const looksLikeScheme = /^[a-z][a-z0-9+.-]*:/i.test(text);
|
|
79
|
+
const hostWithPort = /^[^/?#@:]+:\d+(?:[/?#]|$)/.test(text);
|
|
80
|
+
if (looksLikeScheme && !hostWithPort) {
|
|
81
|
+
const explicit = /^https?:\/\/(.*)$/i.exec(text);
|
|
82
|
+
if (!explicit || explicit[1].startsWith("/")) return INVALID;
|
|
83
|
+
candidate = text;
|
|
84
|
+
} else {
|
|
85
|
+
if (text.startsWith("/")) return INVALID;
|
|
86
|
+
candidate = `https://${text}`;
|
|
87
|
+
}
|
|
88
|
+
let url;
|
|
89
|
+
try {
|
|
90
|
+
url = new URL(candidate);
|
|
91
|
+
} catch {
|
|
92
|
+
return INVALID;
|
|
93
|
+
}
|
|
94
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return INVALID;
|
|
95
|
+
if (url.username || url.password || url.port) return INVALID;
|
|
96
|
+
if (url.hostname.startsWith("[")) return INVALID;
|
|
97
|
+
const host = normalizeSiteHost(url.hostname);
|
|
98
|
+
if (!host || host.length > 253) return INVALID;
|
|
99
|
+
const labels = host.split(".");
|
|
100
|
+
if (labels.length < 2 || !labels.every((label) => HOST_LABEL.test(label))) return INVALID;
|
|
101
|
+
if (!PUBLIC_TLD.test(labels[labels.length - 1])) return INVALID;
|
|
102
|
+
if (isBlockedPublicUrlHost(host)) return INVALID;
|
|
103
|
+
const canonical = `${url.protocol}//${host}${url.pathname.replace(/\/+$/, "")}`;
|
|
104
|
+
if (canonical.length > BOOKING_WEBSITE_URL_MAX) return TOO_LONG;
|
|
105
|
+
const shown = labels[0] === "www" && labels.length > 2 ? labels.slice(1).join(".") : host;
|
|
106
|
+
return { ok: true, url: canonical, host: shown };
|
|
107
|
+
}
|
|
108
|
+
var BOOKING_BUSINESS_EXEMPT_SOURCES = ["portal"];
|
|
109
|
+
function bookingBusinessExempt(source, verifiedMember) {
|
|
110
|
+
return verifiedMember === true && typeof source === "string" && BOOKING_BUSINESS_EXEMPT_SOURCES.includes(source);
|
|
111
|
+
}
|
|
112
|
+
function checkBookingBusinessAnswers(step, input, opts = {}) {
|
|
113
|
+
const enforced = bookingAsksBusiness(step) && !bookingBusinessExempt(opts.source, opts.verifiedMember);
|
|
114
|
+
const required = enforced && parseBookingBusinessStep(step) === "required";
|
|
115
|
+
const errors = {};
|
|
116
|
+
const dropped = {};
|
|
117
|
+
let company = normalizeBookingCompany(input?.company);
|
|
118
|
+
if (company !== null && characters(company) > BOOKING_COMPANY_MAX) {
|
|
119
|
+
if (enforced) errors.company = "too_long";
|
|
120
|
+
else dropped.company = "too_long";
|
|
121
|
+
company = null;
|
|
122
|
+
} else if (company === null && required) {
|
|
123
|
+
errors.company = "required";
|
|
124
|
+
}
|
|
125
|
+
const noWebsite = input?.noWebsite === true;
|
|
126
|
+
let website = null;
|
|
127
|
+
if (!noWebsite) {
|
|
128
|
+
const parsed = normalizeGuestWebsite(input?.website);
|
|
129
|
+
if (parsed === null) website = null;
|
|
130
|
+
else if (parsed.ok) website = parsed.url;
|
|
131
|
+
else if (enforced) errors.website = parsed.reason;
|
|
132
|
+
else dropped.website = parsed.reason;
|
|
133
|
+
}
|
|
134
|
+
if (errors.company || errors.website) return { ok: false, errors };
|
|
135
|
+
return { ok: true, value: { company, website, noWebsite, dropped } };
|
|
136
|
+
}
|
|
137
|
+
var BOOKING_BUSINESS_ERROR_TEXT = {
|
|
138
|
+
company_required: "Please add your company name, or your own name if you work for yourself.",
|
|
139
|
+
company_too_long: `That name's a little long. Please keep it to ${BOOKING_COMPANY_MAX} characters or fewer.`,
|
|
140
|
+
website_invalid: "That doesn't look like a web address. Try something like yourcompany.com.",
|
|
141
|
+
website_too_long: "That address is too long. The main address is enough, like yourcompany.com."
|
|
142
|
+
};
|
|
143
|
+
function describeBookingBusinessErrors(errors) {
|
|
144
|
+
const text = {};
|
|
145
|
+
if (errors.company) text.company = errors.company === "required" ? BOOKING_BUSINESS_ERROR_TEXT.company_required : BOOKING_BUSINESS_ERROR_TEXT.company_too_long;
|
|
146
|
+
if (errors.website) text.website = errors.website === "invalid" ? BOOKING_BUSINESS_ERROR_TEXT.website_invalid : BOOKING_BUSINESS_ERROR_TEXT.website_too_long;
|
|
147
|
+
return text;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/contracts/booking-intake.ts
|
|
151
|
+
var BOOKING_INTAKE_CONTRACT_VERSION = 1;
|
|
152
|
+
var BOOKING_INTAKE_JSON_SCHEMA = {
|
|
153
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
154
|
+
$id: "https://sonor.io/schemas/booking-intake.v1.json",
|
|
155
|
+
title: "BookingGuestBusinessAnswers",
|
|
156
|
+
description: "What a guest tells a booking about their business: a company name (their own name if they work for themselves), a website address if they have one, and a flag for 'we don't have a website yet', which wins over any website sent with it.",
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
company: {
|
|
160
|
+
type: ["string", "null"],
|
|
161
|
+
maxLength: BOOKING_COMPANY_MAX,
|
|
162
|
+
description: "Company name. Required when the booking type's business step is required. The length is measured after cleaning: extra whitespace and control characters don't count."
|
|
163
|
+
},
|
|
164
|
+
website: {
|
|
165
|
+
type: ["string", "null"],
|
|
166
|
+
maxLength: BOOKING_WEBSITE_INPUT_MAX,
|
|
167
|
+
description: "A public http or https address, or a bare domain like example.com. Credentials, ports, IP addresses and the local names localhost, .local and .internal are refused. The query and fragment are dropped and the path is kept. The length is measured after trimming."
|
|
168
|
+
},
|
|
169
|
+
noWebsite: {
|
|
170
|
+
type: ["boolean", "null"],
|
|
171
|
+
description: "True when the guest has no website yet. A website sent with it is ignored."
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function bookingBusinessDetails(row, contact) {
|
|
176
|
+
const fromRow = {
|
|
177
|
+
company: normalizeBookingCompany(row?.guest_company),
|
|
178
|
+
website: readWebsite(row?.guest_website),
|
|
179
|
+
noWebsite: row?.guest_no_website === true
|
|
180
|
+
};
|
|
181
|
+
const fromContact = {
|
|
182
|
+
company: normalizeBookingCompany(contact?.company),
|
|
183
|
+
website: readWebsite(contact?.website)
|
|
184
|
+
};
|
|
185
|
+
const company = fromRow.company ?? fromContact.company;
|
|
186
|
+
const website = fromRow.website ?? (fromRow.noWebsite ? null : fromContact.website);
|
|
187
|
+
const noWebsite = fromRow.noWebsite && website === null;
|
|
188
|
+
const guestAnswered = fromRow.company !== null || fromRow.website !== null || fromRow.noWebsite;
|
|
189
|
+
const contactSupplied = fromRow.company === null && fromContact.company !== null || fromRow.website === null && website !== null;
|
|
190
|
+
return {
|
|
191
|
+
company,
|
|
192
|
+
website: website?.url ?? null,
|
|
193
|
+
websiteHost: website?.host ?? null,
|
|
194
|
+
noWebsite,
|
|
195
|
+
from: guestAnswered ? "booking" : contactSupplied ? "contact" : null
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function readWebsite(value) {
|
|
199
|
+
const parsed = normalizeGuestWebsite(value);
|
|
200
|
+
return parsed && parsed.ok ? { url: parsed.url, host: parsed.host } : null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { BOOKING_BUSINESS_ERROR_TEXT, BOOKING_BUSINESS_EXEMPT_SOURCES, BOOKING_BUSINESS_STEPS, BOOKING_COMPANY_MAX, BOOKING_GUEST_BUSINESS_FIELDS, BOOKING_INTAKE_CONTRACT_VERSION, BOOKING_INTAKE_JSON_SCHEMA, BOOKING_WEBSITE_INPUT_MAX, BOOKING_WEBSITE_URL_MAX, bookingAsksBusiness, bookingBusinessDetails, bookingBusinessExempt, checkBookingBusinessAnswers, describeBookingBusinessErrors, normalizeBookingCompany, normalizeGuestWebsite, parseBookingBusinessStep };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a person's yes may not contain: the ONE quote screen. Pure, no dependencies.
|
|
3
|
+
*
|
|
4
|
+
* The quote is the person's own words, stored on the Ledger beside their approval and copied into the acceptance, so it must not carry a secret. It is also a place an agent
|
|
5
|
+
* must NEVER edit the person's words, so a refusal has to be rare and for a real secret shape: a campaign name ("Q4 BOGO PPC", "SEM_BRAND_EXACT_US",
|
|
6
|
+
* "BrandSearchQ4Retargeting2026") is not one. What it refuses:
|
|
7
|
+
* - credentials by their published shapes (provider key and token prefixes, JWTs, private keys, URLs with a password in them, ?token= parameters);
|
|
8
|
+
* - credentials said in words ("the Stripe key is ...", "password is ...", "wp login: admin/...", a door code);
|
|
9
|
+
* - a payment card (13 to 19 digits that pass Luhn AND begin like a card brand's numbers, so an 18-digit Meta campaign id is not a card), an IBAN (it must pass the mod-97
|
|
10
|
+
* check), a US routing or account number said as one, a social security number;
|
|
11
|
+
* - a token that is named and then given ("auth token 4f9a..."), a bare run of hex of 32 or more, and a bare run of 32 or more letters, digits and token punctuation that is
|
|
12
|
+
* noise and not a name.
|
|
13
|
+
* What it deliberately does NOT refuse: a bare random token of 20 to 31 characters with no prefix and no word before it. Such a token cannot be told from an abbreviation-heavy
|
|
14
|
+
* name by shape, and refusing names is the worse failure here. Prefixes, JWTs and a word like "key" or "token" before the value still catch the real ones.
|
|
15
|
+
*
|
|
16
|
+
* CALLERS CAP THE LENGTH FIRST (refuseQuote does): some patterns here are quadratic on a long run with no space, which a 1,000-character quote cannot make slow.
|
|
17
|
+
*/
|
|
18
|
+
/** The longest quote, in UTF-16 units: a sentence or two of "yes, go ahead with the $500", not an essay. */
|
|
19
|
+
export declare const QUOTE_MAX_LENGTH = 1000;
|
|
20
|
+
/**
|
|
21
|
+
* Why a quote can't be stored as the person said it (a credential, a card number, a password), or null when it can. Run it on a quote already cut to QUOTE_MAX_LENGTH
|
|
22
|
+
* (refuseQuote does that first).
|
|
23
|
+
*/
|
|
24
|
+
export declare function quoteSecretReason(text: string): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a quote may come in, in the order that matters: the length cap FIRST (an O(1) comparison, so a quote of any size is refused before anything reads it), then the
|
|
27
|
+
* screen. A value that is not text is not this function's to judge. Use it at intake, once; never on evidence already stored.
|
|
28
|
+
*/
|
|
29
|
+
export declare function refuseQuote(quote: unknown): 'too_long' | 'secret' | null;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/contracts/quote-screen.ts
|
|
4
|
+
var QUOTE_MAX_LENGTH = 1e3;
|
|
5
|
+
var PROJECT_API_KEY = /\bsonor_[0-9a-f]{8}_[A-Za-z0-9_-]{8,}/i;
|
|
6
|
+
var NOT_A_VALUE = String.raw`(?!(?:stored|kept|saved|in|on|at|with|managed|shared|the|a|an|our|my|your|their|his|her|not|never|changed|changing|reset|rotated|expired|expiring|expires|updated|required|same|different|written|listed|available|below|above|here|there|somewhere|secret|private|safe|set|missing|wrong|old|new|weak|strong|secure|long|short|case|valid|invalid|correct|incorrect|working|broken|locked|unlocked|known|unknown|temporary|blank|empty|are|were|will|should|must|can|needed|needs|sent|emailed|texted|given|handled|taped)\b)`;
|
|
7
|
+
var KEY_OWNERS = "api|secret|access|private|license|licence|publishable|signing|webhook|admin|master|encryption|ssh|gpg|pgp|client|app|integration|stripe|resend|openai|anthropic|google|aws|square|twilio|sendgrid|mailchimp|mailgun|postmark|github|gitlab|slack|shopify|netlify|vercel|supabase|sonor|cloudflare|zapier|hubspot|paypal|quickbooks|wordpress|wp";
|
|
8
|
+
var CREDENTIAL_NOUN = String.raw`(?:(?:${KEY_OWNERS})\s+(?:api\s+)?(?:key|token|secret)|(?:access|refresh|bearer|auth|api|session|deploy|personal)\s+token|token|client\s+secret|secret)s?`;
|
|
9
|
+
var FOR_SOMETHING = String.raw`(?:\s+(?:for|to|on|at|of|in|with)\s+[^.,;:\n]{1,40}?)?`;
|
|
10
|
+
var IS = String.raw`(?:\b(?:is|was)\b|=|:)`;
|
|
11
|
+
var CREDENTIAL_IS_VALUE = new RegExp(String.raw`\b${CREDENTIAL_NOUN}\b${FOR_SOMETHING}\s*${IS}\s*${NOT_A_VALUE}(?=\S*[\d_])\S{6,}`, "i");
|
|
12
|
+
var PASSWORD_NOUN = String.raw`(?:password|passcode|passwd|pwd|passphrase|pw|(?:admin|wp|wordpress|wifi|wi-fi|login|account|user|email|site|portal|router|db|database|ftp|sftp|ssh|server|cpanel|hosting|dashboard|app|vpn)\s+pass)`;
|
|
13
|
+
var PASSWORD_IS_VALUE = new RegExp(String.raw`\b${PASSWORD_NOUN}\b${FOR_SOMETHING}\s*(?:${IS}|-)\s*${NOT_A_VALUE}\S{3,}`, "i");
|
|
14
|
+
var USER_THEN_PASS = new RegExp(String.raw`\b(?:user(?:name)?|login)\b\s*${IS}?\s*\S+[\s,;/]+(?:and\s+)?(?:the\s+)?(?:pass(?:word)?|pw|pwd)\b\s*(?:${IS}|-)?\s*${NOT_A_VALUE}(?=\S*[A-Za-z])(?=\S*[\d!@#$%^&*?_])\S{4,}`, "i");
|
|
15
|
+
var LOGIN_USER_SECRET = new RegExp(String.raw`\b(?:login|log-?in|credentials|creds)\b\s*${IS}\s*(?!(?:at|on|in|is|the|a|an|via|through|page|screen|link|url)\b)[^\s/]+\s+(?:and\s+|with\s+)?(?=\S*[A-Za-z])(?=\S*[\d!@#$%^&*?])\S{4,}`, "i");
|
|
16
|
+
var LOGIN_EMAIL_SECRET = new RegExp(String.raw`\b(?:login|log-?in|credentials|creds|sign-?in|account)\b[^.\n]{0,40}?[\w.+-]+@[\w-]+(?:\.[\w-]+)+\s*(?:with|and|/|,|:|\|)\s*(?:the\s+)?(?:(?:pass(?:word)?|pw)\s+)?(?:${IS}\s*)?(?=\S*[A-Za-z])(?=\S*[\d!@#$%^&*?])\S{4,}`, "i");
|
|
17
|
+
var NAMED_CODE = new RegExp(String.raw`\b(?:door|gate|alarm|lock|lockbox|lock box|garage|keypad|entry|building|wifi|wi-fi|security|access)\s+(?:code|combo|combination|pin)\b[^.;\n]{0,40}?${IS}\s*#?\d{3,8}`, "i");
|
|
18
|
+
var BARE_LOCK_CODE = new RegExp(String.raw`\b(?:lockbox|lock box|keypad)\b\s*(?:code\s*)?${IS}\s*#?\d{3,8}\b`, "i");
|
|
19
|
+
var NAMED_SERVICE_SECRET = new RegExp(String.raw`\b[A-Z][A-Za-z0-9]+\s+(?:[Aa][Pp][Ii]\s+)?(?:[Kk]ey|[Tt]oken|[Ss]ecret|[Pp]ass(?:word)?)\b\s*${IS}\s*(?=\S*\d)\S{12,}`);
|
|
20
|
+
var SECRET_PATTERNS = [
|
|
21
|
+
// Provider keys
|
|
22
|
+
{ re: /\b(?:sk|rk|pk)_(?:live|test)_/i, what: "an API key" },
|
|
23
|
+
{ re: /\bsk-(?:proj-|ant-|svcacct-)?[A-Za-z0-9_-]{16,}/, what: "an API key" },
|
|
24
|
+
{ re: /\bre_(?=[A-Za-z0-9_]*[0-9A-Z])[A-Za-z0-9_]{12,}/, what: "an API key" },
|
|
25
|
+
{ re: /\bwhsec_[A-Za-z0-9+/=]{10,}/, what: "an API key" },
|
|
26
|
+
{ re: /\bAIza[0-9A-Za-z_-]{30,}/, what: "an API key" },
|
|
27
|
+
{ re: /\bEAAA[A-Za-z0-9_-]{30,}/, what: "an API key" },
|
|
28
|
+
{ re: /\bsq0(?:atp|csp|idp)-[A-Za-z0-9_-]{16,}/, what: "an API key" },
|
|
29
|
+
{ re: /\bSG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/, what: "an API key" },
|
|
30
|
+
{ re: /\b[0-9a-f]{32}-us\d{1,2}\b/, what: "an API key" },
|
|
31
|
+
{ re: /\bshp(?:at|ss|ca|pa)_[A-Fa-f0-9]{20,}/, what: "an API key" },
|
|
32
|
+
{ re: /\bnpm_[A-Za-z0-9]{30,}/, what: "an API key" },
|
|
33
|
+
{ re: /\bsonor_[A-Za-z0-9]{6,}_[A-Za-z0-9_-]{8,}/, what: "an API key" },
|
|
34
|
+
{ re: /\bsb_(?:secret|publishable)_[A-Za-z0-9_-]{8,}/, what: "an API key" },
|
|
35
|
+
// Access tokens
|
|
36
|
+
{ re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/, what: "an access key" },
|
|
37
|
+
{ re: /\bgh[pousr]_[A-Za-z0-9]{20,}/, what: "an access token" },
|
|
38
|
+
{ re: /\bgithub_pat_[A-Za-z0-9_]{20,}/, what: "an access token" },
|
|
39
|
+
{ re: /\bglpat-[A-Za-z0-9_-]{20,}/, what: "an access token" },
|
|
40
|
+
{ re: /\bxox[abprse]-[A-Za-z0-9-]{10,}/, what: "an access token" },
|
|
41
|
+
{ re: /hooks\.slack\.com\/services\/[A-Za-z0-9/]{16,}/, what: "an access token" },
|
|
42
|
+
{ re: /\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*/i, what: "a login token" },
|
|
43
|
+
{ re: /\bBasic\s+[A-Za-z0-9+/]{16,}={0,2}/, what: "a login token" },
|
|
44
|
+
{ re: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}/, what: "a login token" },
|
|
45
|
+
{ re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/, what: "a private key" },
|
|
46
|
+
{ re: /[?&](?:api[_-]?key|access[_-]?token|auth[_-]?token|token|secret|client[_-]?secret|password|pwd|sig|signature)=[^&\s]{6,}/i, what: "an API key" },
|
|
47
|
+
// Credentials said in words: "<service> key is ...", "the token: ...", "password is ...".
|
|
48
|
+
{ re: CREDENTIAL_IS_VALUE, what: "an access token" },
|
|
49
|
+
{ re: PASSWORD_IS_VALUE, what: "a password" },
|
|
50
|
+
{ re: USER_THEN_PASS, what: "a login" },
|
|
51
|
+
{ re: LOGIN_EMAIL_SECRET, what: "a login" },
|
|
52
|
+
{ re: LOGIN_USER_SECRET, what: "a login" },
|
|
53
|
+
{ re: NAMED_CODE, what: "a PIN or access code" },
|
|
54
|
+
{ re: BARE_LOCK_CODE, what: "a PIN or access code" },
|
|
55
|
+
{ re: /\bkey-[a-z0-9]{24,}\b/i, what: "an API key" },
|
|
56
|
+
{ re: NAMED_SERVICE_SECRET, what: "an access token" },
|
|
57
|
+
{ re: /\b(?:password|passcode|passwd|pwd|passphrase|pw)\b[:=]?\s+(?=\S*[\d!@#$%^&*?])\S{4,}/i, what: "a password" },
|
|
58
|
+
{ re: /\b(?:pin|pin code|pin number|passcode|gate code|door code|alarm code|lock code|lockbox code|access code|security code|garage code|cvv|cvc)\b\s*(?:is|was|=|:|-)?\s*#?\d{3,8}\b/i, what: "a PIN or access code" },
|
|
59
|
+
{ re: /\b[a-z][a-z0-9+.-]{0,31}:\/\/[^\s/:@]+:[^\s/@]+@/i, what: "a login" },
|
|
60
|
+
// Bank and identity numbers
|
|
61
|
+
{ re: /\b(?:routing|aba|rtn|transit)\s*(?:number|no\.?|#)?\s*(?:is|:|=|-)?\s*\d{9}\b/i, what: "a bank routing number" },
|
|
62
|
+
{ re: /\b(?:bank|checking|savings|acct|account)\s*(?:number|no\.?|#)\s*(?:is|:|=|-)?\s*\d[\d -]{4,20}\d\b/i, what: "a bank account number" },
|
|
63
|
+
{ re: /\bbank\s+account\s*(?:is|:|=|-)?\s*\d{6,17}\b/i, what: "a bank account number" },
|
|
64
|
+
{ re: /\b\d{3}-\d{2}-\d{4}\b/, what: "a social security number" },
|
|
65
|
+
{ re: /\b(?:ssn|social security(?: number)?)\b\D{0,15}\d{9}\b/i, what: "a social security number" }
|
|
66
|
+
];
|
|
67
|
+
function luhn(digits) {
|
|
68
|
+
let sum = 0;
|
|
69
|
+
let double = false;
|
|
70
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
71
|
+
let d = digits.charCodeAt(i) - 48;
|
|
72
|
+
if (double) {
|
|
73
|
+
d *= 2;
|
|
74
|
+
if (d > 9) d -= 9;
|
|
75
|
+
}
|
|
76
|
+
sum += d;
|
|
77
|
+
double = !double;
|
|
78
|
+
}
|
|
79
|
+
return sum % 10 === 0;
|
|
80
|
+
}
|
|
81
|
+
function looksLikeCard(digits) {
|
|
82
|
+
const n = digits.length;
|
|
83
|
+
const head = (k) => Number(digits.slice(0, k));
|
|
84
|
+
if (digits[0] === "4") return n === 13 || n === 16 || n === 19;
|
|
85
|
+
if (n === 16 && (head(2) >= 51 && head(2) <= 55 || head(4) >= 2221 && head(4) <= 2720)) return true;
|
|
86
|
+
if (n === 15 && (head(2) === 34 || head(2) === 37)) return true;
|
|
87
|
+
if (n >= 16 && n <= 19 && (head(4) === 6011 || head(3) >= 644 && head(3) <= 649 || head(2) === 65 || head(2) === 62)) return true;
|
|
88
|
+
if (n >= 16 && n <= 19 && head(4) >= 3528 && head(4) <= 3589) return true;
|
|
89
|
+
if (n >= 14 && n <= 19 && (head(3) >= 300 && head(3) <= 305 || head(2) === 36 || head(2) === 38 || head(2) === 39)) return true;
|
|
90
|
+
if (n >= 12 && n <= 19 && [5018, 5020, 5038, 5893, 6304, 6759, 6761, 6762, 6763].includes(head(4))) return true;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
function hasIban(s) {
|
|
94
|
+
for (const [candidate] of s.matchAll(/\b[A-Z]{2}\d{2} ?(?:[A-Z0-9]{4} ?){2,7}[A-Z0-9]{1,4}\b/g)) {
|
|
95
|
+
const compact = candidate.replace(/ /g, "");
|
|
96
|
+
if (compact.length < 15 || compact.length > 34) continue;
|
|
97
|
+
const rearranged = compact.slice(4) + compact.slice(0, 4);
|
|
98
|
+
let remainder = 0;
|
|
99
|
+
for (const ch of rearranged) {
|
|
100
|
+
const value = ch >= "A" && ch <= "Z" ? String(ch.charCodeAt(0) - 55) : ch;
|
|
101
|
+
for (const digit of value) remainder = (remainder * 10 + (digit.charCodeAt(0) - 48)) % 97;
|
|
102
|
+
}
|
|
103
|
+
if (remainder === 1) return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
function quoteSecretReason(text) {
|
|
108
|
+
const s = typeof text === "string" ? text : "";
|
|
109
|
+
if (!s) return null;
|
|
110
|
+
for (const { re, what } of SECRET_PATTERNS) if (re.test(s)) return what;
|
|
111
|
+
if (PROJECT_API_KEY.test(s)) return "an API key";
|
|
112
|
+
for (const m of s.matchAll(/\b(?:\d[ -]?){13,19}\b/g)) {
|
|
113
|
+
const digits = m[0].replace(/\D/g, "");
|
|
114
|
+
if (digits.length >= 13 && digits.length <= 19 && luhn(digits) && looksLikeCard(digits)) return "a payment card number";
|
|
115
|
+
}
|
|
116
|
+
if (hasIban(s)) return "a bank account number";
|
|
117
|
+
if (hasLoginPair(s)) return "a login";
|
|
118
|
+
if (hasKeyedToken(s) || hasNoiseRun(s)) return "an access token";
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
function refuseQuote(quote) {
|
|
122
|
+
if (typeof quote !== "string") return null;
|
|
123
|
+
if (quote.length > QUOTE_MAX_LENGTH) return "too_long";
|
|
124
|
+
return quoteSecretReason(quote) === null ? null : "secret";
|
|
125
|
+
}
|
|
126
|
+
function hasKeyedToken(s) {
|
|
127
|
+
const prose = s.replace(/\b(?:https?:\/\/|www\.)\S+/gi, " ");
|
|
128
|
+
if (/\b(?=[0-9a-f]*[a-f])(?=[0-9a-f]*\d)[0-9a-f]{32,}\b/i.test(prose)) return true;
|
|
129
|
+
for (const m of prose.matchAll(/\b(?:token|key|secret|sid)s?\b\s*(?:\b(?:is|was)\b|=|:|-)?\s*([A-Za-z0-9_-]{24,})/gi)) {
|
|
130
|
+
const token = m[1];
|
|
131
|
+
if (!/\d/.test(token) || !/[A-Za-z]/.test(token) || (token.match(/-/g)?.length ?? 0) > 1) continue;
|
|
132
|
+
if (looksLikeName(token) || wordShare(token) >= WORDS_SHARE) continue;
|
|
133
|
+
if (shannonEntropy(token) >= 3.3) return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
var LOGIN_WORD = /\b(?:login|log-?in|logins|username|user ?name|user id|credentials|creds|sign-?in)\b/gi;
|
|
138
|
+
function hasLoginPair(s) {
|
|
139
|
+
for (const m of s.matchAll(LOGIN_WORD)) {
|
|
140
|
+
const after = s.slice((m.index ?? 0) + m[0].length, (m.index ?? 0) + m[0].length + 80);
|
|
141
|
+
const pair = /(?:^|[\s:=])([^\s/:=]{2,})\s*\/\s*([^\s/]{3,})/.exec(after);
|
|
142
|
+
if (!pair) continue;
|
|
143
|
+
const [, user, password] = pair;
|
|
144
|
+
if (user.includes(".") && !user.includes("@")) continue;
|
|
145
|
+
if (/^https?$/i.test(user) || /^[a-z0-9-]+\.[a-z]{2,}/i.test(password)) continue;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
function wordShare(run) {
|
|
151
|
+
const body = run.replace(/[-_]/g, "");
|
|
152
|
+
let inWords = 0;
|
|
153
|
+
for (const m of body.matchAll(/[A-Z][a-z]{2,}|[a-z]{4,}/g)) inWords += m[0].length;
|
|
154
|
+
return body.length ? inWords / body.length : 0;
|
|
155
|
+
}
|
|
156
|
+
var WORDS_SHARE = 0.5;
|
|
157
|
+
function looksLikeName(run) {
|
|
158
|
+
const pieces = run.split(/[-_]/).filter(Boolean);
|
|
159
|
+
return pieces.length >= 3 && pieces.every((piece) => piece.length <= 14);
|
|
160
|
+
}
|
|
161
|
+
var NOISE_RUN_LENGTH = 32;
|
|
162
|
+
var NOISE_RUN_ENTROPY = 4;
|
|
163
|
+
function hasNoiseRun(s) {
|
|
164
|
+
const prose = stripAddresses(s.replace(/\b(?:https?:\/\/|www\.)\S+/gi, " "));
|
|
165
|
+
for (const [run] of prose.matchAll(new RegExp(`[A-Za-z0-9_\\-+/=]{${NOISE_RUN_LENGTH},}`, "g"))) {
|
|
166
|
+
if (!/\d/.test(run) || !/[A-Za-z]/.test(run)) continue;
|
|
167
|
+
if (looksLikeName(run) || wordShare(run) >= WORDS_SHARE) continue;
|
|
168
|
+
if (shannonEntropy(run) >= NOISE_RUN_ENTROPY) return true;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
function stripAddresses(s) {
|
|
173
|
+
if (!s.includes("@")) return s;
|
|
174
|
+
return s.replace(/\S+/g, (chunk) => {
|
|
175
|
+
const at = chunk.indexOf("@", 1);
|
|
176
|
+
if (at === -1) return chunk;
|
|
177
|
+
const dot = chunk.indexOf(".", at + 2);
|
|
178
|
+
return dot !== -1 && dot <= chunk.length - 2 ? " " : chunk;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function shannonEntropy(text) {
|
|
182
|
+
const counts = /* @__PURE__ */ new Map();
|
|
183
|
+
for (const ch of text) counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
184
|
+
let bits = 0;
|
|
185
|
+
for (const n of counts.values()) {
|
|
186
|
+
const p = n / text.length;
|
|
187
|
+
bits -= p * Math.log2(p);
|
|
188
|
+
}
|
|
189
|
+
return bits;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
exports.QUOTE_MAX_LENGTH = QUOTE_MAX_LENGTH;
|
|
193
|
+
exports.quoteSecretReason = quoteSecretReason;
|
|
194
|
+
exports.refuseQuote = refuseQuote;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// src/contracts/quote-screen.ts
|
|
2
|
+
var QUOTE_MAX_LENGTH = 1e3;
|
|
3
|
+
var PROJECT_API_KEY = /\bsonor_[0-9a-f]{8}_[A-Za-z0-9_-]{8,}/i;
|
|
4
|
+
var NOT_A_VALUE = String.raw`(?!(?:stored|kept|saved|in|on|at|with|managed|shared|the|a|an|our|my|your|their|his|her|not|never|changed|changing|reset|rotated|expired|expiring|expires|updated|required|same|different|written|listed|available|below|above|here|there|somewhere|secret|private|safe|set|missing|wrong|old|new|weak|strong|secure|long|short|case|valid|invalid|correct|incorrect|working|broken|locked|unlocked|known|unknown|temporary|blank|empty|are|were|will|should|must|can|needed|needs|sent|emailed|texted|given|handled|taped)\b)`;
|
|
5
|
+
var KEY_OWNERS = "api|secret|access|private|license|licence|publishable|signing|webhook|admin|master|encryption|ssh|gpg|pgp|client|app|integration|stripe|resend|openai|anthropic|google|aws|square|twilio|sendgrid|mailchimp|mailgun|postmark|github|gitlab|slack|shopify|netlify|vercel|supabase|sonor|cloudflare|zapier|hubspot|paypal|quickbooks|wordpress|wp";
|
|
6
|
+
var CREDENTIAL_NOUN = String.raw`(?:(?:${KEY_OWNERS})\s+(?:api\s+)?(?:key|token|secret)|(?:access|refresh|bearer|auth|api|session|deploy|personal)\s+token|token|client\s+secret|secret)s?`;
|
|
7
|
+
var FOR_SOMETHING = String.raw`(?:\s+(?:for|to|on|at|of|in|with)\s+[^.,;:\n]{1,40}?)?`;
|
|
8
|
+
var IS = String.raw`(?:\b(?:is|was)\b|=|:)`;
|
|
9
|
+
var CREDENTIAL_IS_VALUE = new RegExp(String.raw`\b${CREDENTIAL_NOUN}\b${FOR_SOMETHING}\s*${IS}\s*${NOT_A_VALUE}(?=\S*[\d_])\S{6,}`, "i");
|
|
10
|
+
var PASSWORD_NOUN = String.raw`(?:password|passcode|passwd|pwd|passphrase|pw|(?:admin|wp|wordpress|wifi|wi-fi|login|account|user|email|site|portal|router|db|database|ftp|sftp|ssh|server|cpanel|hosting|dashboard|app|vpn)\s+pass)`;
|
|
11
|
+
var PASSWORD_IS_VALUE = new RegExp(String.raw`\b${PASSWORD_NOUN}\b${FOR_SOMETHING}\s*(?:${IS}|-)\s*${NOT_A_VALUE}\S{3,}`, "i");
|
|
12
|
+
var USER_THEN_PASS = new RegExp(String.raw`\b(?:user(?:name)?|login)\b\s*${IS}?\s*\S+[\s,;/]+(?:and\s+)?(?:the\s+)?(?:pass(?:word)?|pw|pwd)\b\s*(?:${IS}|-)?\s*${NOT_A_VALUE}(?=\S*[A-Za-z])(?=\S*[\d!@#$%^&*?_])\S{4,}`, "i");
|
|
13
|
+
var LOGIN_USER_SECRET = new RegExp(String.raw`\b(?:login|log-?in|credentials|creds)\b\s*${IS}\s*(?!(?:at|on|in|is|the|a|an|via|through|page|screen|link|url)\b)[^\s/]+\s+(?:and\s+|with\s+)?(?=\S*[A-Za-z])(?=\S*[\d!@#$%^&*?])\S{4,}`, "i");
|
|
14
|
+
var LOGIN_EMAIL_SECRET = new RegExp(String.raw`\b(?:login|log-?in|credentials|creds|sign-?in|account)\b[^.\n]{0,40}?[\w.+-]+@[\w-]+(?:\.[\w-]+)+\s*(?:with|and|/|,|:|\|)\s*(?:the\s+)?(?:(?:pass(?:word)?|pw)\s+)?(?:${IS}\s*)?(?=\S*[A-Za-z])(?=\S*[\d!@#$%^&*?])\S{4,}`, "i");
|
|
15
|
+
var NAMED_CODE = new RegExp(String.raw`\b(?:door|gate|alarm|lock|lockbox|lock box|garage|keypad|entry|building|wifi|wi-fi|security|access)\s+(?:code|combo|combination|pin)\b[^.;\n]{0,40}?${IS}\s*#?\d{3,8}`, "i");
|
|
16
|
+
var BARE_LOCK_CODE = new RegExp(String.raw`\b(?:lockbox|lock box|keypad)\b\s*(?:code\s*)?${IS}\s*#?\d{3,8}\b`, "i");
|
|
17
|
+
var NAMED_SERVICE_SECRET = new RegExp(String.raw`\b[A-Z][A-Za-z0-9]+\s+(?:[Aa][Pp][Ii]\s+)?(?:[Kk]ey|[Tt]oken|[Ss]ecret|[Pp]ass(?:word)?)\b\s*${IS}\s*(?=\S*\d)\S{12,}`);
|
|
18
|
+
var SECRET_PATTERNS = [
|
|
19
|
+
// Provider keys
|
|
20
|
+
{ re: /\b(?:sk|rk|pk)_(?:live|test)_/i, what: "an API key" },
|
|
21
|
+
{ re: /\bsk-(?:proj-|ant-|svcacct-)?[A-Za-z0-9_-]{16,}/, what: "an API key" },
|
|
22
|
+
{ re: /\bre_(?=[A-Za-z0-9_]*[0-9A-Z])[A-Za-z0-9_]{12,}/, what: "an API key" },
|
|
23
|
+
{ re: /\bwhsec_[A-Za-z0-9+/=]{10,}/, what: "an API key" },
|
|
24
|
+
{ re: /\bAIza[0-9A-Za-z_-]{30,}/, what: "an API key" },
|
|
25
|
+
{ re: /\bEAAA[A-Za-z0-9_-]{30,}/, what: "an API key" },
|
|
26
|
+
{ re: /\bsq0(?:atp|csp|idp)-[A-Za-z0-9_-]{16,}/, what: "an API key" },
|
|
27
|
+
{ re: /\bSG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/, what: "an API key" },
|
|
28
|
+
{ re: /\b[0-9a-f]{32}-us\d{1,2}\b/, what: "an API key" },
|
|
29
|
+
{ re: /\bshp(?:at|ss|ca|pa)_[A-Fa-f0-9]{20,}/, what: "an API key" },
|
|
30
|
+
{ re: /\bnpm_[A-Za-z0-9]{30,}/, what: "an API key" },
|
|
31
|
+
{ re: /\bsonor_[A-Za-z0-9]{6,}_[A-Za-z0-9_-]{8,}/, what: "an API key" },
|
|
32
|
+
{ re: /\bsb_(?:secret|publishable)_[A-Za-z0-9_-]{8,}/, what: "an API key" },
|
|
33
|
+
// Access tokens
|
|
34
|
+
{ re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/, what: "an access key" },
|
|
35
|
+
{ re: /\bgh[pousr]_[A-Za-z0-9]{20,}/, what: "an access token" },
|
|
36
|
+
{ re: /\bgithub_pat_[A-Za-z0-9_]{20,}/, what: "an access token" },
|
|
37
|
+
{ re: /\bglpat-[A-Za-z0-9_-]{20,}/, what: "an access token" },
|
|
38
|
+
{ re: /\bxox[abprse]-[A-Za-z0-9-]{10,}/, what: "an access token" },
|
|
39
|
+
{ re: /hooks\.slack\.com\/services\/[A-Za-z0-9/]{16,}/, what: "an access token" },
|
|
40
|
+
{ re: /\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*/i, what: "a login token" },
|
|
41
|
+
{ re: /\bBasic\s+[A-Za-z0-9+/]{16,}={0,2}/, what: "a login token" },
|
|
42
|
+
{ re: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}/, what: "a login token" },
|
|
43
|
+
{ re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/, what: "a private key" },
|
|
44
|
+
{ re: /[?&](?:api[_-]?key|access[_-]?token|auth[_-]?token|token|secret|client[_-]?secret|password|pwd|sig|signature)=[^&\s]{6,}/i, what: "an API key" },
|
|
45
|
+
// Credentials said in words: "<service> key is ...", "the token: ...", "password is ...".
|
|
46
|
+
{ re: CREDENTIAL_IS_VALUE, what: "an access token" },
|
|
47
|
+
{ re: PASSWORD_IS_VALUE, what: "a password" },
|
|
48
|
+
{ re: USER_THEN_PASS, what: "a login" },
|
|
49
|
+
{ re: LOGIN_EMAIL_SECRET, what: "a login" },
|
|
50
|
+
{ re: LOGIN_USER_SECRET, what: "a login" },
|
|
51
|
+
{ re: NAMED_CODE, what: "a PIN or access code" },
|
|
52
|
+
{ re: BARE_LOCK_CODE, what: "a PIN or access code" },
|
|
53
|
+
{ re: /\bkey-[a-z0-9]{24,}\b/i, what: "an API key" },
|
|
54
|
+
{ re: NAMED_SERVICE_SECRET, what: "an access token" },
|
|
55
|
+
{ re: /\b(?:password|passcode|passwd|pwd|passphrase|pw)\b[:=]?\s+(?=\S*[\d!@#$%^&*?])\S{4,}/i, what: "a password" },
|
|
56
|
+
{ re: /\b(?:pin|pin code|pin number|passcode|gate code|door code|alarm code|lock code|lockbox code|access code|security code|garage code|cvv|cvc)\b\s*(?:is|was|=|:|-)?\s*#?\d{3,8}\b/i, what: "a PIN or access code" },
|
|
57
|
+
{ re: /\b[a-z][a-z0-9+.-]{0,31}:\/\/[^\s/:@]+:[^\s/@]+@/i, what: "a login" },
|
|
58
|
+
// Bank and identity numbers
|
|
59
|
+
{ re: /\b(?:routing|aba|rtn|transit)\s*(?:number|no\.?|#)?\s*(?:is|:|=|-)?\s*\d{9}\b/i, what: "a bank routing number" },
|
|
60
|
+
{ re: /\b(?:bank|checking|savings|acct|account)\s*(?:number|no\.?|#)\s*(?:is|:|=|-)?\s*\d[\d -]{4,20}\d\b/i, what: "a bank account number" },
|
|
61
|
+
{ re: /\bbank\s+account\s*(?:is|:|=|-)?\s*\d{6,17}\b/i, what: "a bank account number" },
|
|
62
|
+
{ re: /\b\d{3}-\d{2}-\d{4}\b/, what: "a social security number" },
|
|
63
|
+
{ re: /\b(?:ssn|social security(?: number)?)\b\D{0,15}\d{9}\b/i, what: "a social security number" }
|
|
64
|
+
];
|
|
65
|
+
function luhn(digits) {
|
|
66
|
+
let sum = 0;
|
|
67
|
+
let double = false;
|
|
68
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
69
|
+
let d = digits.charCodeAt(i) - 48;
|
|
70
|
+
if (double) {
|
|
71
|
+
d *= 2;
|
|
72
|
+
if (d > 9) d -= 9;
|
|
73
|
+
}
|
|
74
|
+
sum += d;
|
|
75
|
+
double = !double;
|
|
76
|
+
}
|
|
77
|
+
return sum % 10 === 0;
|
|
78
|
+
}
|
|
79
|
+
function looksLikeCard(digits) {
|
|
80
|
+
const n = digits.length;
|
|
81
|
+
const head = (k) => Number(digits.slice(0, k));
|
|
82
|
+
if (digits[0] === "4") return n === 13 || n === 16 || n === 19;
|
|
83
|
+
if (n === 16 && (head(2) >= 51 && head(2) <= 55 || head(4) >= 2221 && head(4) <= 2720)) return true;
|
|
84
|
+
if (n === 15 && (head(2) === 34 || head(2) === 37)) return true;
|
|
85
|
+
if (n >= 16 && n <= 19 && (head(4) === 6011 || head(3) >= 644 && head(3) <= 649 || head(2) === 65 || head(2) === 62)) return true;
|
|
86
|
+
if (n >= 16 && n <= 19 && head(4) >= 3528 && head(4) <= 3589) return true;
|
|
87
|
+
if (n >= 14 && n <= 19 && (head(3) >= 300 && head(3) <= 305 || head(2) === 36 || head(2) === 38 || head(2) === 39)) return true;
|
|
88
|
+
if (n >= 12 && n <= 19 && [5018, 5020, 5038, 5893, 6304, 6759, 6761, 6762, 6763].includes(head(4))) return true;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
function hasIban(s) {
|
|
92
|
+
for (const [candidate] of s.matchAll(/\b[A-Z]{2}\d{2} ?(?:[A-Z0-9]{4} ?){2,7}[A-Z0-9]{1,4}\b/g)) {
|
|
93
|
+
const compact = candidate.replace(/ /g, "");
|
|
94
|
+
if (compact.length < 15 || compact.length > 34) continue;
|
|
95
|
+
const rearranged = compact.slice(4) + compact.slice(0, 4);
|
|
96
|
+
let remainder = 0;
|
|
97
|
+
for (const ch of rearranged) {
|
|
98
|
+
const value = ch >= "A" && ch <= "Z" ? String(ch.charCodeAt(0) - 55) : ch;
|
|
99
|
+
for (const digit of value) remainder = (remainder * 10 + (digit.charCodeAt(0) - 48)) % 97;
|
|
100
|
+
}
|
|
101
|
+
if (remainder === 1) return true;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
function quoteSecretReason(text) {
|
|
106
|
+
const s = typeof text === "string" ? text : "";
|
|
107
|
+
if (!s) return null;
|
|
108
|
+
for (const { re, what } of SECRET_PATTERNS) if (re.test(s)) return what;
|
|
109
|
+
if (PROJECT_API_KEY.test(s)) return "an API key";
|
|
110
|
+
for (const m of s.matchAll(/\b(?:\d[ -]?){13,19}\b/g)) {
|
|
111
|
+
const digits = m[0].replace(/\D/g, "");
|
|
112
|
+
if (digits.length >= 13 && digits.length <= 19 && luhn(digits) && looksLikeCard(digits)) return "a payment card number";
|
|
113
|
+
}
|
|
114
|
+
if (hasIban(s)) return "a bank account number";
|
|
115
|
+
if (hasLoginPair(s)) return "a login";
|
|
116
|
+
if (hasKeyedToken(s) || hasNoiseRun(s)) return "an access token";
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function refuseQuote(quote) {
|
|
120
|
+
if (typeof quote !== "string") return null;
|
|
121
|
+
if (quote.length > QUOTE_MAX_LENGTH) return "too_long";
|
|
122
|
+
return quoteSecretReason(quote) === null ? null : "secret";
|
|
123
|
+
}
|
|
124
|
+
function hasKeyedToken(s) {
|
|
125
|
+
const prose = s.replace(/\b(?:https?:\/\/|www\.)\S+/gi, " ");
|
|
126
|
+
if (/\b(?=[0-9a-f]*[a-f])(?=[0-9a-f]*\d)[0-9a-f]{32,}\b/i.test(prose)) return true;
|
|
127
|
+
for (const m of prose.matchAll(/\b(?:token|key|secret|sid)s?\b\s*(?:\b(?:is|was)\b|=|:|-)?\s*([A-Za-z0-9_-]{24,})/gi)) {
|
|
128
|
+
const token = m[1];
|
|
129
|
+
if (!/\d/.test(token) || !/[A-Za-z]/.test(token) || (token.match(/-/g)?.length ?? 0) > 1) continue;
|
|
130
|
+
if (looksLikeName(token) || wordShare(token) >= WORDS_SHARE) continue;
|
|
131
|
+
if (shannonEntropy(token) >= 3.3) return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
var LOGIN_WORD = /\b(?:login|log-?in|logins|username|user ?name|user id|credentials|creds|sign-?in)\b/gi;
|
|
136
|
+
function hasLoginPair(s) {
|
|
137
|
+
for (const m of s.matchAll(LOGIN_WORD)) {
|
|
138
|
+
const after = s.slice((m.index ?? 0) + m[0].length, (m.index ?? 0) + m[0].length + 80);
|
|
139
|
+
const pair = /(?:^|[\s:=])([^\s/:=]{2,})\s*\/\s*([^\s/]{3,})/.exec(after);
|
|
140
|
+
if (!pair) continue;
|
|
141
|
+
const [, user, password] = pair;
|
|
142
|
+
if (user.includes(".") && !user.includes("@")) continue;
|
|
143
|
+
if (/^https?$/i.test(user) || /^[a-z0-9-]+\.[a-z]{2,}/i.test(password)) continue;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
function wordShare(run) {
|
|
149
|
+
const body = run.replace(/[-_]/g, "");
|
|
150
|
+
let inWords = 0;
|
|
151
|
+
for (const m of body.matchAll(/[A-Z][a-z]{2,}|[a-z]{4,}/g)) inWords += m[0].length;
|
|
152
|
+
return body.length ? inWords / body.length : 0;
|
|
153
|
+
}
|
|
154
|
+
var WORDS_SHARE = 0.5;
|
|
155
|
+
function looksLikeName(run) {
|
|
156
|
+
const pieces = run.split(/[-_]/).filter(Boolean);
|
|
157
|
+
return pieces.length >= 3 && pieces.every((piece) => piece.length <= 14);
|
|
158
|
+
}
|
|
159
|
+
var NOISE_RUN_LENGTH = 32;
|
|
160
|
+
var NOISE_RUN_ENTROPY = 4;
|
|
161
|
+
function hasNoiseRun(s) {
|
|
162
|
+
const prose = stripAddresses(s.replace(/\b(?:https?:\/\/|www\.)\S+/gi, " "));
|
|
163
|
+
for (const [run] of prose.matchAll(new RegExp(`[A-Za-z0-9_\\-+/=]{${NOISE_RUN_LENGTH},}`, "g"))) {
|
|
164
|
+
if (!/\d/.test(run) || !/[A-Za-z]/.test(run)) continue;
|
|
165
|
+
if (looksLikeName(run) || wordShare(run) >= WORDS_SHARE) continue;
|
|
166
|
+
if (shannonEntropy(run) >= NOISE_RUN_ENTROPY) return true;
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
function stripAddresses(s) {
|
|
171
|
+
if (!s.includes("@")) return s;
|
|
172
|
+
return s.replace(/\S+/g, (chunk) => {
|
|
173
|
+
const at = chunk.indexOf("@", 1);
|
|
174
|
+
if (at === -1) return chunk;
|
|
175
|
+
const dot = chunk.indexOf(".", at + 2);
|
|
176
|
+
return dot !== -1 && dot <= chunk.length - 2 ? " " : chunk;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function shannonEntropy(text) {
|
|
180
|
+
const counts = /* @__PURE__ */ new Map();
|
|
181
|
+
for (const ch of text) counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
182
|
+
let bits = 0;
|
|
183
|
+
for (const n of counts.values()) {
|
|
184
|
+
const p = n / text.length;
|
|
185
|
+
bits -= p * Math.log2(p);
|
|
186
|
+
}
|
|
187
|
+
return bits;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { QUOTE_MAX_LENGTH, quoteSecretReason, refuseQuote };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared vectors for quote-screen.ts: what a person's yes may say and what it may not. Plain data, no logic, no dependencies.
|
|
3
|
+
* Fixed strings only (no randomness), so a failure names the exact quote.
|
|
4
|
+
*/
|
|
5
|
+
/** Campaign names the way ad accounts write them: words, abbreviations, all-caps, separators or none. None is a secret. */
|
|
6
|
+
export declare const QUOTE_CAMPAIGN_NAMES: readonly string[];
|
|
7
|
+
/** Sentences a person says it in. */
|
|
8
|
+
export declare const QUOTE_SENTENCE_FRAMES: ReadonlyArray<(name: string) => string>;
|
|
9
|
+
/** Other things people say in a yes that are not secrets. */
|
|
10
|
+
export declare const QUOTE_ACCEPTED: readonly string[];
|
|
11
|
+
/** What may never go in, with the reason the screen names. */
|
|
12
|
+
export declare const QUOTE_REFUSED: ReadonlyArray<{
|
|
13
|
+
quote: string;
|
|
14
|
+
reason: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Quotes past the cap, which are refused as too long before anything reads them. */
|
|
17
|
+
/**
|
|
18
|
+
* Quotes the screen refuses today that a person could say innocently, kept here so the limit is visible and a change to it is a decision. All are one unbroken run of 24 or more
|
|
19
|
+
* characters with no "-" or "_" in it, long enough that its shape (letters, digits, high entropy) is the shape of a random token: entropy does not separate them (these names measure
|
|
20
|
+
* 4.0 to 4.6 bits a character; random upper-case-and-digit runs 4.0 to 4.4). The agent tells the person the screen cannot take that, and asks for the name with separators or its id.
|
|
21
|
+
*/
|
|
22
|
+
export declare const QUOTE_KNOWN_LIMITS: readonly string[];
|
|
23
|
+
export declare const QUOTE_TOO_LONG: readonly string[];
|