saaslayer 0.4.2 → 0.4.3
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/package.json +5 -6
- package/src/commands/operations.js +1 -1
- package/src/commands/users-management.js +2 -2
- package/src/users-import/ids.js +1 -1
- package/vendor/config/login-domain.js +213 -0
- package/vendor/discovery/index.d.mts +109 -0
- package/vendor/discovery/index.mjs +409 -0
- package/vendor/ids/index.d.ts +21 -0
- package/vendor/ids/index.js +237 -0
- package/vendor/migrations/backups.js +118 -0
- package/vendor/migrations/child.js +78 -0
- package/vendor/migrations/credentials.js +103 -0
- package/vendor/migrations/errors.js +30 -0
- package/vendor/migrations/exec-child.js +78 -0
- package/vendor/migrations/gate.js +51 -0
- package/vendor/migrations/index.js +30 -0
- package/vendor/migrations/inventory.js +92 -0
- package/vendor/migrations/log.js +14 -0
- package/vendor/migrations/release.js +45 -0
- package/vendor/migrations/report.js +129 -0
- package/vendor/migrations/rules.js +104 -0
- package/vendor/migrations/run.js +311 -0
- package/vendor/migrations/session-policy.js +37 -0
- package/vendor/migrations/step-guard.js +82 -0
- package/vendor/operations/activity.d.ts +21 -0
- package/vendor/operations/activity.js +126 -0
- package/vendor/operations/index.d.ts +60 -0
- package/vendor/operations/index.js +471 -0
- package/vendor/permissions-engine-core/account-status.js +270 -0
- package/vendor/permissions-engine-core/delegation.js +174 -0
- package/vendor/permissions-engine-core/direct-mode-contract.js +237 -0
- package/vendor/permissions-engine-core/sso-claims.js +206 -0
- package/vendor/user-management/cognito/emails/token-registry.js +48 -0
- package/vendor/user-management/email/validate.js +207 -0
- package/vendor/user-management/extensibility/hook-contract.js +720 -0
- package/vendor/user-management/extensibility/safe-webhook.js +85 -0
- package/vendor/user-management/identity/admission.js +215 -0
- package/vendor/user-management/identity/attr.js +27 -0
- package/vendor/user-management/identity/attribute-registry.js +115 -0
- package/vendor/user-management/identity/email.js +25 -0
- package/vendor/user-management/identity/ensure-suid.js +74 -0
- package/vendor/user-management/identity/pointers.js +192 -0
- package/vendor/user-management/identity/stitch-provider.js +275 -0
- package/vendor/user-management/management/apply-request.js +227 -0
- package/vendor/user-management/management/core-profile.js +110 -0
- package/vendor/user-management/management/index.js +23 -0
- package/vendor/user-management/management/purposes.js +94 -0
- package/vendor/user-management/management/registry.js +569 -0
- package/vendor/user-management/store/table.js +332 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email customization validation (E2). VALIDATE-ONLY, NEVER SANITIZE (D-l): reject an invalid
|
|
3
|
+
* customization (422 at save; discard + fall back at render) but never strip/rewrite customer markup.
|
|
4
|
+
* Pure — no AWS. Enforces: required {{tokens}} present, Cognito subject(140)/body(20000) limits,
|
|
5
|
+
* https/mailto-only links, brand color/URL format.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { getRequiredTokens } = require('../cognito/emails/token-registry')
|
|
9
|
+
|
|
10
|
+
const SUBJECT_MAX = 140
|
|
11
|
+
const BODY_MAX = 20000
|
|
12
|
+
const COLOR_RE = /^#[0-9a-fA-F]{6}$/
|
|
13
|
+
const HEX_KEYS = ['accentColor', 'textColor', 'cardBackground']
|
|
14
|
+
const URL_KEYS = ['logoUrl', 'logoLinkUrl']
|
|
15
|
+
// Every field a brand may carry (validated above or free text).
|
|
16
|
+
const BRAND_FIELDS = ['companyName', 'productName', 'supportLink', ...URL_KEYS, ...HEX_KEYS]
|
|
17
|
+
// Attributes that never fetch or navigate — a {{token}} there renders as inert markup, not a request.
|
|
18
|
+
const INERT_ATTRS = ['id', 'class', 'title', 'alt', 'name', 'lang', 'dir']
|
|
19
|
+
// Attributes that load a remote image when the email is opened.
|
|
20
|
+
const IMAGE_ATTRS = ['src', 'srcset', 'background', 'poster']
|
|
21
|
+
const ATTR_RE = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/g
|
|
22
|
+
const CTA_ONLY_RE = /^\{\{\s*ctaUrl\s*\}\}$/
|
|
23
|
+
|
|
24
|
+
/** True if `str` contains the {{token}} placeholder (whitespace-tolerant). */
|
|
25
|
+
function hasToken(str, token) {
|
|
26
|
+
return new RegExp(`\\{\\{\\s*${token}\\s*\\}\\}`).test(String(str || ''))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The first href/src whose scheme is not https:/mailto: (ignoring {{token}} placeholders), or null.
|
|
31
|
+
* @param {string} html
|
|
32
|
+
*/
|
|
33
|
+
function findBadLink(html) {
|
|
34
|
+
if (typeof html !== 'string') return null
|
|
35
|
+
const re = /(?:href|src)\s*=\s*["']([^"']+)["']/gi
|
|
36
|
+
let m
|
|
37
|
+
while ((m = re.exec(html)) !== null) {
|
|
38
|
+
const url = m[1].trim()
|
|
39
|
+
if (url.startsWith('{{')) continue // a {{token}} whose value is supplied + guarded at render
|
|
40
|
+
if (!/^(https:|mailto:)/i.test(url)) return url
|
|
41
|
+
}
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Every attribute (name + raw value) in an HTML fragment, quoted or unquoted.
|
|
47
|
+
* @param {string} html
|
|
48
|
+
* @returns {Array<{ name: string, value: string }>}
|
|
49
|
+
*/
|
|
50
|
+
function attributesOf(html) {
|
|
51
|
+
const out = []
|
|
52
|
+
if (typeof html !== 'string') return out
|
|
53
|
+
const re = new RegExp(ATTR_RE.source, 'g')
|
|
54
|
+
let m
|
|
55
|
+
while ((m = re.exec(html)) !== null) {
|
|
56
|
+
out.push({ name: m[1].toLowerCase(), value: m[2] ?? m[3] ?? m[4] ?? '' })
|
|
57
|
+
}
|
|
58
|
+
return out
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The first attribute that interpolates a {{token}} where the value could leave the email (a URL, style or
|
|
63
|
+
* handler), or null. Allowed: the server-built CTA as the WHOLE href (`href="{{ctaUrl}}"`) and inert attrs
|
|
64
|
+
* (id/class/alt/...). Anything else (`src="https://x/?c={{code}}"`, `href="https://x/{{ctaUrl}}"`,
|
|
65
|
+
* `style="url({{code}})"`) would ship the secret code/link to a third party when the email is opened/clicked.
|
|
66
|
+
* @param {string} html
|
|
67
|
+
* @returns {{ name: string, value: string }|null}
|
|
68
|
+
*/
|
|
69
|
+
function findTokenInAttribute(html) {
|
|
70
|
+
for (const attr of attributesOf(html)) {
|
|
71
|
+
if (!/\{\{/.test(attr.value)) continue
|
|
72
|
+
if (attr.name === 'href' && CTA_ONLY_RE.test(attr.value.trim())) continue
|
|
73
|
+
if (INERT_ATTRS.includes(attr.name) || attr.name.startsWith('aria-') || attr.name.startsWith('data-')) continue
|
|
74
|
+
return attr
|
|
75
|
+
}
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The first image URL whose host is not on the allowlist (or is not https), or null.
|
|
81
|
+
* @param {string} html
|
|
82
|
+
* @param {string[]} imageHosts allowed hostnames
|
|
83
|
+
* @returns {string|null}
|
|
84
|
+
*/
|
|
85
|
+
function findBadImageHost(html, imageHosts) {
|
|
86
|
+
const allowed = (imageHosts || []).map((h) => String(h).toLowerCase())
|
|
87
|
+
for (const attr of attributesOf(html)) {
|
|
88
|
+
if (!IMAGE_ATTRS.includes(attr.name)) continue
|
|
89
|
+
for (const candidate of attr.value.split(',').map((v) => v.trim().split(/\s+/)[0]).filter(Boolean)) {
|
|
90
|
+
let url
|
|
91
|
+
try { url = new URL(candidate) } catch { return candidate }
|
|
92
|
+
if (url.protocol !== 'https:' || !allowed.includes(url.hostname.toLowerCase())) return candidate
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Default image-host allowlist: the host of the deploy-time header logo (EMAIL_HEADER_IMAGE).
|
|
100
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
101
|
+
* @returns {string[]}
|
|
102
|
+
*/
|
|
103
|
+
function defaultImageHosts(env = process.env) {
|
|
104
|
+
try { return env.EMAIL_HEADER_IMAGE ? [new URL(env.EMAIL_HEADER_IMAGE).hostname] : [] } catch { return [] }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Image-host allowlist for a render/save: the effective brand logo's host plus the deploy-time default.
|
|
109
|
+
* @param {{ logoUrl?: string }|null|undefined} brand
|
|
110
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
111
|
+
* @returns {string[]}
|
|
112
|
+
*/
|
|
113
|
+
function imageHostsFor(brand, env = process.env) {
|
|
114
|
+
const hosts = defaultImageHosts(env)
|
|
115
|
+
try { if (brand && brand.logoUrl) hosts.push(new URL(brand.logoUrl).hostname) } catch { /* invalid logo url adds nothing */ }
|
|
116
|
+
return Array.from(new Set(hosts))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Validate a tier-1 content override for a trigger. An absent override is valid (uses seed).
|
|
121
|
+
* @param {{ triggerSource: string, content: Record<string, any>|undefined|null, imageHosts?: string[] }} input
|
|
122
|
+
* imageHosts: allowed image hostnames (defaults to the deploy-time header logo's host)
|
|
123
|
+
* @returns {{ ok: boolean, errors: Array<{field:string, code:string, token?:string, value?:string}> }}
|
|
124
|
+
*/
|
|
125
|
+
function validateContent({ triggerSource, content, imageHosts }) {
|
|
126
|
+
const errors = []
|
|
127
|
+
if (content == null) return { ok: true, errors }
|
|
128
|
+
if (typeof content !== 'object') {
|
|
129
|
+
return { ok: false, errors: [{ field: 'content', code: 'INVALID_TYPE' }] }
|
|
130
|
+
}
|
|
131
|
+
const subject = content.subject
|
|
132
|
+
const body = content.body
|
|
133
|
+
const haystack = `${subject == null ? '' : subject}\n${body == null ? '' : body}`
|
|
134
|
+
// Required tokens must be referenced in the customer's subject/body, else the rendered email would
|
|
135
|
+
// omit the confirm link/code -> Cognito InvalidLambdaResponseException.
|
|
136
|
+
for (const token of getRequiredTokens(triggerSource)) {
|
|
137
|
+
if (!hasToken(haystack, token)) {
|
|
138
|
+
errors.push({ field: 'body', code: 'MISSING_REQUIRED_TOKEN', token })
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (typeof subject === 'string' && subject.length > SUBJECT_MAX) {
|
|
142
|
+
errors.push({ field: 'subject', code: 'SUBJECT_TOO_LONG' })
|
|
143
|
+
}
|
|
144
|
+
if (typeof body === 'string' && body.length > BODY_MAX) {
|
|
145
|
+
errors.push({ field: 'body', code: 'BODY_TOO_LONG' })
|
|
146
|
+
}
|
|
147
|
+
// Subject is plain text that mail clients auto-link: no URLs at all (a {{code}} beside one is harvestable).
|
|
148
|
+
if (typeof subject === 'string' && /(https?:\/\/|www\.)/i.test(subject)) {
|
|
149
|
+
errors.push({ field: 'subject', code: 'LINK_IN_SUBJECT' })
|
|
150
|
+
}
|
|
151
|
+
const hosts = imageHosts || defaultImageHosts()
|
|
152
|
+
// body + title are both injected as HTML into the layout: same link / token-placement / image rules.
|
|
153
|
+
for (const field of ['body', 'title']) {
|
|
154
|
+
const html = content[field]
|
|
155
|
+
const badLink = findBadLink(html)
|
|
156
|
+
if (badLink) errors.push({ field, code: 'BAD_LINK_SCHEME', value: badLink })
|
|
157
|
+
const tokenAttr = findTokenInAttribute(html)
|
|
158
|
+
if (tokenAttr) errors.push({ field, code: 'TOKEN_IN_ATTRIBUTE', value: `${tokenAttr.name}=${tokenAttr.value}` })
|
|
159
|
+
const badImage = findBadImageHost(html, hosts)
|
|
160
|
+
if (badImage) errors.push({ field, code: 'IMAGE_HOST_NOT_ALLOWED', value: badImage })
|
|
161
|
+
}
|
|
162
|
+
return { ok: errors.length === 0, errors }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Validate a tier-0 brand override: hex colors + https URLs.
|
|
167
|
+
* @param {{ brand: Record<string, any>|undefined|null }} input
|
|
168
|
+
*/
|
|
169
|
+
function validateBrand({ brand }) {
|
|
170
|
+
const errors = []
|
|
171
|
+
if (brand == null) return { ok: true, errors }
|
|
172
|
+
if (typeof brand !== 'object') return { ok: false, errors: [{ field: 'brand', code: 'INVALID_TYPE' }] }
|
|
173
|
+
for (const key of HEX_KEYS) {
|
|
174
|
+
if (brand[key] != null && brand[key] !== '' && !COLOR_RE.test(String(brand[key]))) {
|
|
175
|
+
errors.push({ field: key, code: 'BAD_COLOR', value: String(brand[key]) })
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
for (const key of URL_KEYS) {
|
|
179
|
+
if (brand[key] != null && brand[key] !== '' && !/^https:\/\//i.test(String(brand[key]))) {
|
|
180
|
+
errors.push({ field: key, code: 'BAD_URL', value: String(brand[key]) })
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (brand.supportLink != null && brand.supportLink !== '' && !/^(https:\/\/|mailto:)/i.test(String(brand.supportLink))) {
|
|
184
|
+
errors.push({ field: 'supportLink', code: 'BAD_URL', value: String(brand.supportLink) })
|
|
185
|
+
}
|
|
186
|
+
return { ok: errors.length === 0, errors }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Post-render guard: the final subject/body must be within Cognito's hard limits and the body must
|
|
191
|
+
* contain every required token's VALUE (not just the placeholder). Used at render (fail-open) and send.
|
|
192
|
+
* @param {{ triggerSource: string, subject: string, body: string, values: Record<string, unknown> }} input
|
|
193
|
+
*/
|
|
194
|
+
function validateRendered({ triggerSource, subject, body, values = {} }) {
|
|
195
|
+
const errors = []
|
|
196
|
+
if (typeof subject === 'string' && subject.length > SUBJECT_MAX) errors.push({ field: 'subject', code: 'SUBJECT_TOO_LONG' })
|
|
197
|
+
if (typeof body === 'string' && body.length > BODY_MAX) errors.push({ field: 'body', code: 'BODY_TOO_LONG' })
|
|
198
|
+
for (const token of getRequiredTokens(triggerSource)) {
|
|
199
|
+
const value = values[token]
|
|
200
|
+
if (value != null && value !== '' && !String(body).includes(String(value))) {
|
|
201
|
+
errors.push({ field: 'body', code: 'MISSING_REQUIRED_VALUE', token })
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { ok: errors.length === 0, errors }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = { BRAND_FIELDS, validateContent, validateBrand, validateRendered, findBadLink, findTokenInAttribute, findBadImageHost, defaultImageHosts, imageHostsFor, hasToken, SUBJECT_MAX, BODY_MAX }
|