@crombolo/server 0.17.0 → 0.19.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/package.json +12 -12
- package/src/adapters/documents.ts +6 -2
- package/src/components.ts +11 -4
- package/src/config.ts +82 -81
- package/src/email-ses.ts +4 -3
- package/src/index.ts +1 -0
- package/src/member-auth.ts +7 -26
- package/src/ports.ts +5 -1
- package/src/seo.ts +5 -5
- package/src/server.ts +33 -6
- package/src/settings.ts +921 -0
- package/src/two-factor.ts +17 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@crombolo/api-delivery": "0.
|
|
34
|
-
"@crombolo/api-management": "0.
|
|
35
|
-
"@crombolo/assistant": "0.
|
|
36
|
-
"@crombolo/auth": "0.
|
|
37
|
-
"@crombolo/backoffice-host": "0.
|
|
38
|
-
"@crombolo/contracts": "0.
|
|
39
|
-
"@crombolo/core": "0.
|
|
40
|
-
"@crombolo/data": "0.
|
|
41
|
-
"@crombolo/render": "0.
|
|
42
|
-
"@crombolo/schema": "0.
|
|
43
|
-
"@crombolo/transfer": "0.
|
|
33
|
+
"@crombolo/api-delivery": "0.19.0",
|
|
34
|
+
"@crombolo/api-management": "0.19.0",
|
|
35
|
+
"@crombolo/assistant": "0.19.0",
|
|
36
|
+
"@crombolo/auth": "0.19.0",
|
|
37
|
+
"@crombolo/backoffice-host": "0.19.0",
|
|
38
|
+
"@crombolo/contracts": "0.19.0",
|
|
39
|
+
"@crombolo/core": "0.19.0",
|
|
40
|
+
"@crombolo/data": "0.19.0",
|
|
41
|
+
"@crombolo/render": "0.19.0",
|
|
42
|
+
"@crombolo/schema": "0.19.0",
|
|
43
|
+
"@crombolo/transfer": "0.19.0",
|
|
44
44
|
"@logtape/logtape": "^2.3.8"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -464,8 +464,12 @@ export function createDocumentPort(
|
|
|
464
464
|
return toTreeItems(repo, await repo.nodes.byKeys(keys))
|
|
465
465
|
},
|
|
466
466
|
|
|
467
|
-
async collection(
|
|
468
|
-
|
|
467
|
+
async collection(
|
|
468
|
+
parentKey: string | null,
|
|
469
|
+
paging: SkipTake,
|
|
470
|
+
excludeKeys: readonly string[] = [],
|
|
471
|
+
): Promise<Page<DocumentAggregate>> {
|
|
472
|
+
const page = await repo.children(parentKey, paging.skip, paging.take, excludeKeys)
|
|
469
473
|
const items: DocumentAggregate[] = []
|
|
470
474
|
for (const row of page.items) {
|
|
471
475
|
const aggregate = await repo.load(row)
|
package/src/components.ts
CHANGED
|
@@ -230,10 +230,13 @@ export default function ${name}({ form, fields, site }: EmailProps) {
|
|
|
230
230
|
`
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/** The folder e-mail templates live in, as an alias prefix. */
|
|
234
|
+
export const EMAIL_FOLDER = 'emails/'
|
|
235
|
+
|
|
233
236
|
/**
|
|
234
|
-
* The components the forms designer offers as e-mail designs: those
|
|
235
|
-
*
|
|
236
|
-
* one that is set. A layout takes `EmailLayoutProps`, so it is not offered.
|
|
237
|
+
* The components the forms designer offers as e-mail designs: those in
|
|
238
|
+
* `components/emails/`, and any a form already names, so a picker never loses
|
|
239
|
+
* the one that is set. A layout there takes `EmailLayoutProps`, so it is not offered.
|
|
237
240
|
*/
|
|
238
241
|
export function listEmailTemplates(
|
|
239
242
|
root: string,
|
|
@@ -242,7 +245,11 @@ export function listEmailTemplates(
|
|
|
242
245
|
const components = listComponents(root)
|
|
243
246
|
const found = new Set<string>()
|
|
244
247
|
for (const component of components)
|
|
245
|
-
if (
|
|
248
|
+
if (
|
|
249
|
+
component.alias.startsWith(EMAIL_FOLDER) &&
|
|
250
|
+
!/\bEmailLayoutProps\b/.test(readFileSync(component.path, 'utf8'))
|
|
251
|
+
)
|
|
252
|
+
found.add(component.alias)
|
|
246
253
|
const present = new Set(components.map((component) => component.alias))
|
|
247
254
|
for (const alias of named) if (present.has(alias)) found.add(alias)
|
|
248
255
|
const items = [...found].sort().map((alias) => ({ alias, name: readableName(alias) }))
|
package/src/config.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { GitConfig } from './git-routes.ts'
|
|
|
14
14
|
import { checkIdentityProviders, type IdentityProvider } from './identity-providers.ts'
|
|
15
15
|
import type { MediaStore } from './media-store.ts'
|
|
16
16
|
import type { SchemaStore } from './schema-store.ts'
|
|
17
|
+
import { setting } from './settings.ts'
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Runtime settings for a site. Umbraco's equivalents live in appsettings.json;
|
|
@@ -497,11 +498,11 @@ export function loadConfig(
|
|
|
497
498
|
cwd = process.cwd(),
|
|
498
499
|
): CromboloConfig {
|
|
499
500
|
const fromEnv: CromboloConfig = {
|
|
500
|
-
port: Number(
|
|
501
|
-
maxRequestBodyBytes:
|
|
502
|
-
? Number(
|
|
501
|
+
port: Number(setting('PORT') ?? DEFAULTS.port),
|
|
502
|
+
maxRequestBodyBytes: setting('CROMBOLO_MAX_REQUEST_BODY_MB')
|
|
503
|
+
? Number(setting('CROMBOLO_MAX_REQUEST_BODY_MB')) * 1024 * 1024
|
|
503
504
|
: DEFAULTS.maxRequestBodyBytes,
|
|
504
|
-
backOfficePath:
|
|
505
|
+
backOfficePath: setting('CROMBOLO_BACKOFFICE_PATH') ?? DEFAULTS.backOfficePath,
|
|
505
506
|
defaultUiLanguage: DEFAULTS.defaultUiLanguage,
|
|
506
507
|
keepUserLoggedIn: DEFAULTS.keepUserLoggedIn,
|
|
507
508
|
allowLocalLogin: DEFAULTS.allowLocalLogin,
|
|
@@ -509,135 +510,135 @@ export function loadConfig(
|
|
|
509
510
|
versionCheckPeriod: DEFAULTS.versionCheckPeriod,
|
|
510
511
|
umbracoCssPath: DEFAULTS.umbracoCssPath,
|
|
511
512
|
signalRSkipNegotiation: DEFAULTS.signalRSkipNegotiation,
|
|
512
|
-
development:
|
|
513
|
-
sqliteFile:
|
|
514
|
-
adminLogin:
|
|
515
|
-
adminPassword:
|
|
513
|
+
development: setting('NODE_ENV') !== 'production',
|
|
514
|
+
sqliteFile: setting('CROMBOLO_SQLITE_FILE') ?? DEFAULTS.sqliteFile,
|
|
515
|
+
adminLogin: setting('CROMBOLO_ADMIN_LOGIN') ?? DEFAULTS.adminLogin,
|
|
516
|
+
adminPassword: setting('CROMBOLO_ADMIN_PASSWORD'),
|
|
516
517
|
apiClient:
|
|
517
|
-
|
|
518
|
+
setting('CROMBOLO_API_CLIENT_ID') || setting('CROMBOLO_API_CLIENT_SECRET')
|
|
518
519
|
? {
|
|
519
|
-
id:
|
|
520
|
-
secret:
|
|
520
|
+
id: setting('CROMBOLO_API_CLIENT_ID') ?? '',
|
|
521
|
+
secret: setting('CROMBOLO_API_CLIENT_SECRET') ?? '',
|
|
521
522
|
}
|
|
522
523
|
: undefined,
|
|
523
|
-
localAdmin:
|
|
524
|
-
setupCode:
|
|
525
|
-
secretKey:
|
|
526
|
-
secureCookies:
|
|
527
|
-
siteName:
|
|
524
|
+
localAdmin: setting('CROMBOLO_LOCAL_ADMIN') === 'true',
|
|
525
|
+
setupCode: setting('CROMBOLO_SETUP_CODE'),
|
|
526
|
+
secretKey: setting('CROMBOLO_SECRET_KEY'),
|
|
527
|
+
secureCookies: setting('CROMBOLO_INSECURE_COOKIES') !== 'true',
|
|
528
|
+
siteName: setting('CROMBOLO_SITE_NAME') ?? DEFAULTS.siteName,
|
|
528
529
|
siteDir: cwd,
|
|
529
|
-
componentsDir:
|
|
530
|
-
componentsCacheDir:
|
|
530
|
+
componentsDir: setting('CROMBOLO_COMPONENTS_DIR') ?? DEFAULTS.componentsDir,
|
|
531
|
+
componentsCacheDir: setting('CROMBOLO_COMPONENTS_CACHE_DIR') ?? DEFAULTS.componentsCacheDir,
|
|
531
532
|
componentsSnapshot: {
|
|
532
|
-
...(
|
|
533
|
-
? { gateTtlMs: Number(
|
|
533
|
+
...(setting('CROMBOLO_COMPONENTS_GATE_MS')
|
|
534
|
+
? { gateTtlMs: Number(setting('CROMBOLO_COMPONENTS_GATE_MS')) }
|
|
534
535
|
: {}),
|
|
535
|
-
...(
|
|
536
|
-
? { maxGenerations: Number(
|
|
536
|
+
...(setting('CROMBOLO_COMPONENTS_GENERATION_LIMIT')
|
|
537
|
+
? { maxGenerations: Number(setting('CROMBOLO_COMPONENTS_GENERATION_LIMIT')) }
|
|
537
538
|
: {}),
|
|
538
|
-
...(
|
|
539
|
-
? { keep: Number(
|
|
539
|
+
...(setting('CROMBOLO_COMPONENTS_KEEP')
|
|
540
|
+
? { keep: Number(setting('CROMBOLO_COMPONENTS_KEEP')) }
|
|
540
541
|
: {}),
|
|
541
|
-
...(
|
|
542
|
-
? { minSwapIntervalMs: Number(
|
|
542
|
+
...(setting('CROMBOLO_COMPONENTS_SWAP_MS')
|
|
543
|
+
? { minSwapIntervalMs: Number(setting('CROMBOLO_COMPONENTS_SWAP_MS')) }
|
|
543
544
|
: {}),
|
|
544
545
|
},
|
|
545
|
-
renderTimeoutMs: Number(
|
|
546
|
-
schemaDir:
|
|
547
|
-
schemaRevision:
|
|
548
|
-
nodeId:
|
|
549
|
-
role: roleFromEnvironment(
|
|
546
|
+
renderTimeoutMs: Number(setting('CROMBOLO_RENDER_TIMEOUT_MS') ?? DEFAULTS.renderTimeoutMs),
|
|
547
|
+
schemaDir: setting('CROMBOLO_SCHEMA_DIR') ?? DEFAULTS.schemaDir,
|
|
548
|
+
schemaRevision: setting('CROMBOLO_SCHEMA_REVISION') ?? DEFAULTS.schemaRevision,
|
|
549
|
+
nodeId: setting('CROMBOLO_NODE_ID') ?? `${hostname()}:${process.pid}`,
|
|
550
|
+
role: roleFromEnvironment(setting('CROMBOLO_ROLE')),
|
|
550
551
|
git: undefined,
|
|
551
552
|
schemaStore: undefined,
|
|
552
|
-
schemaCacheDir:
|
|
553
|
+
schemaCacheDir: setting('CROMBOLO_SCHEMA_CACHE_DIR') ?? join(tmpdir(), 'crombolo-schema'),
|
|
553
554
|
// Resolved again below, once it is known whether a store was configured.
|
|
554
555
|
schemaWritable:
|
|
555
|
-
|
|
556
|
-
?
|
|
557
|
-
:
|
|
558
|
-
syncSchemaAtBoot:
|
|
559
|
-
dialect:
|
|
560
|
-
pgDump:
|
|
556
|
+
setting('CROMBOLO_SCHEMA_WRITABLE') !== undefined
|
|
557
|
+
? setting('CROMBOLO_SCHEMA_WRITABLE') === 'true'
|
|
558
|
+
: setting('NODE_ENV') !== 'production',
|
|
559
|
+
syncSchemaAtBoot: setting('CROMBOLO_SYNC_SCHEMA_AT_BOOT') !== 'false',
|
|
560
|
+
dialect: setting('CROMBOLO_DB') === 'postgres' ? 'postgres' : 'sqlite',
|
|
561
|
+
pgDump: setting('CROMBOLO_PG_DUMP'),
|
|
561
562
|
upgradePolicy:
|
|
562
|
-
|
|
563
|
-
(
|
|
563
|
+
setting('CROMBOLO_UPGRADE_POLICY') === 'pending-allowed' ||
|
|
564
|
+
(setting('CROMBOLO_UPGRADE_POLICY') === undefined && setting('NODE_ENV') !== 'production')
|
|
564
565
|
? 'pending-allowed'
|
|
565
566
|
: 'strict',
|
|
566
567
|
versionCleanup: {
|
|
567
|
-
enabled:
|
|
568
|
+
enabled: setting('CROMBOLO_VERSION_CLEANUP') === 'true',
|
|
568
569
|
keepAllVersionsNewerThanDays: Number(
|
|
569
|
-
|
|
570
|
+
setting('CROMBOLO_VERSION_CLEANUP_KEEP_ALL_DAYS') ?? DEFAULTS.keepAllVersionsNewerThanDays,
|
|
570
571
|
),
|
|
571
572
|
keepLatestVersionPerDayForDays: Number(
|
|
572
|
-
|
|
573
|
+
setting('CROMBOLO_VERSION_CLEANUP_KEEP_LATEST_DAYS') ??
|
|
573
574
|
DEFAULTS.keepLatestVersionPerDayForDays,
|
|
574
575
|
),
|
|
575
576
|
},
|
|
576
577
|
auditRetentionDays: nonNegative(
|
|
577
|
-
|
|
578
|
+
setting('CROMBOLO_AUDIT_RETENTION_DAYS'),
|
|
578
579
|
DEFAULTS.auditRetentionDays,
|
|
579
580
|
),
|
|
580
|
-
mediaDir:
|
|
581
|
+
mediaDir: setting('CROMBOLO_MEDIA_DIR') ?? DEFAULTS.mediaDir,
|
|
581
582
|
mediaStore: undefined,
|
|
582
|
-
logsDir:
|
|
583
|
-
logLevel: parseLogLevel(
|
|
584
|
-
logToConsole:
|
|
583
|
+
logsDir: setting('CROMBOLO_LOGS_DIR') ?? DEFAULTS.logsDir,
|
|
584
|
+
logLevel: parseLogLevel(setting('CROMBOLO_LOG_LEVEL')),
|
|
585
|
+
logToConsole: setting('CROMBOLO_LOG_TO_CONSOLE') !== 'false',
|
|
585
586
|
diagnostics: {
|
|
586
|
-
traceRequests:
|
|
587
|
-
heapIntervalSeconds: Math.max(0, Number(
|
|
587
|
+
traceRequests: setting('CROMBOLO_TRACE_REQUESTS') === 'true',
|
|
588
|
+
heapIntervalSeconds: Math.max(0, Number(setting('CROMBOLO_HEAP_INTERVAL_SECONDS') ?? 0) || 0),
|
|
588
589
|
},
|
|
589
|
-
stylesheetsDir:
|
|
590
|
-
scriptsDir:
|
|
591
|
-
usernameIsEmail:
|
|
592
|
-
applicationUrl:
|
|
590
|
+
stylesheetsDir: setting('CROMBOLO_CSS_DIR') ?? DEFAULTS.stylesheetsDir,
|
|
591
|
+
scriptsDir: setting('CROMBOLO_SCRIPTS_DIR') ?? DEFAULTS.scriptsDir,
|
|
592
|
+
usernameIsEmail: setting('CROMBOLO_USERNAME_IS_EMAIL') !== 'false',
|
|
593
|
+
applicationUrl: setting('CROMBOLO_APPLICATION_URL') ?? '',
|
|
593
594
|
sendUserLink: undefined,
|
|
594
595
|
email: undefined,
|
|
595
|
-
allowMemberRegistration:
|
|
596
|
+
allowMemberRegistration: setting('CROMBOLO_ALLOW_MEMBER_REGISTRATION') === 'true',
|
|
596
597
|
memberRegistrationType:
|
|
597
|
-
|
|
598
|
-
memberRegistrationGroups: (
|
|
598
|
+
setting('CROMBOLO_MEMBER_REGISTRATION_TYPE') ?? DEFAULTS.memberRegistrationType,
|
|
599
|
+
memberRegistrationGroups: (setting('CROMBOLO_MEMBER_REGISTRATION_GROUPS') ?? '')
|
|
599
600
|
.split(',')
|
|
600
601
|
.map((name) => name.trim())
|
|
601
602
|
.filter(Boolean),
|
|
602
603
|
memberSessionMinutes: Number(
|
|
603
|
-
|
|
604
|
+
setting('CROMBOLO_MEMBER_SESSION_MINUTES') ?? DEFAULTS.memberSessionMinutes,
|
|
604
605
|
),
|
|
605
606
|
maxFailedPasswordAttempts: Number(
|
|
606
|
-
|
|
607
|
+
setting('CROMBOLO_MAX_FAILED_PASSWORD_ATTEMPTS') ?? DEFAULTS.maxFailedPasswordAttempts,
|
|
607
608
|
),
|
|
608
609
|
// No environment variable: a provider is a preset, which is code.
|
|
609
610
|
memberIdentityProviders: [],
|
|
610
611
|
backofficeIdentityProviders: [],
|
|
611
612
|
remote: {
|
|
612
|
-
enabled:
|
|
613
|
-
environment:
|
|
614
|
-
protected:
|
|
615
|
-
approvals:
|
|
616
|
-
maxUploadBytes: Number(
|
|
613
|
+
enabled: setting('CROMBOLO_REMOTE_ENABLED') === 'true',
|
|
614
|
+
environment: setting('CROMBOLO_REMOTE_ENVIRONMENT') || 'production',
|
|
615
|
+
protected: setting('CROMBOLO_REMOTE_PROTECTED') !== 'false',
|
|
616
|
+
approvals: setting('CROMBOLO_REMOTE_APPROVALS') === 'true',
|
|
617
|
+
maxUploadBytes: Number(setting('CROMBOLO_REMOTE_MAX_UPLOAD_GB') ?? 50) * 1024 ** 3,
|
|
617
618
|
},
|
|
618
619
|
redirects: [],
|
|
619
|
-
trackRedirects:
|
|
620
|
-
applyBundleContentOnInstall:
|
|
620
|
+
trackRedirects: setting('CROMBOLO_TRACK_REDIRECTS') !== 'false',
|
|
621
|
+
applyBundleContentOnInstall: setting('CROMBOLO_APPLY_BUNDLE_CONTENT') !== 'false',
|
|
621
622
|
// Resolved again below, once it is known whether a store was configured.
|
|
622
|
-
runtimeInstalls:
|
|
623
|
+
runtimeInstalls: setting('CROMBOLO_RUNTIME_INSTALLS') !== 'false',
|
|
623
624
|
seo: stripUndefined({
|
|
624
|
-
sitemap: envFlag(
|
|
625
|
-
indexable: envFlag(
|
|
625
|
+
sitemap: envFlag(setting('CROMBOLO_SITEMAP')),
|
|
626
|
+
indexable: envFlag(setting('CROMBOLO_INDEXABLE')),
|
|
626
627
|
}),
|
|
627
628
|
deliveryApi: stripUndefined({
|
|
628
|
-
enabled: envFlag(
|
|
629
|
-
apiKey:
|
|
630
|
-
publicAccess: envFlag(
|
|
629
|
+
enabled: envFlag(setting('CROMBOLO_DELIVERY_API')),
|
|
630
|
+
apiKey: setting('CROMBOLO_DELIVERY_API_KEY') || undefined,
|
|
631
|
+
publicAccess: envFlag(setting('CROMBOLO_DELIVERY_API_PUBLIC')),
|
|
631
632
|
media:
|
|
632
|
-
envFlag(
|
|
633
|
+
envFlag(setting('CROMBOLO_DELIVERY_API_MEDIA')) === undefined
|
|
633
634
|
? undefined
|
|
634
|
-
: { enabled: envFlag(
|
|
635
|
+
: { enabled: envFlag(setting('CROMBOLO_DELIVERY_API_MEDIA')) },
|
|
635
636
|
}),
|
|
636
637
|
// No environment variable: a bundle is an import, which is code.
|
|
637
638
|
bundles: [],
|
|
638
|
-
marketplaceUrl:
|
|
639
|
-
packageKeyword:
|
|
640
|
-
npmRegistry:
|
|
639
|
+
marketplaceUrl: setting('CROMBOLO_MARKETPLACE_URL') ?? DEFAULTS.marketplaceUrl,
|
|
640
|
+
packageKeyword: setting('CROMBOLO_PACKAGE_KEYWORD') ?? DEFAULTS.packageKeyword,
|
|
641
|
+
npmRegistry: setting('CROMBOLO_NPM_REGISTRY') ?? DEFAULTS.npmRegistry,
|
|
641
642
|
// No environment variable: enabling it takes a provider, which is code.
|
|
642
643
|
assistant: undefined,
|
|
643
644
|
}
|
|
@@ -661,7 +662,7 @@ export function loadConfig(
|
|
|
661
662
|
// it — that is the point of configuring one. An explicit setting still wins.
|
|
662
663
|
if (
|
|
663
664
|
merged.schemaStore &&
|
|
664
|
-
|
|
665
|
+
setting('CROMBOLO_SCHEMA_WRITABLE') === undefined &&
|
|
665
666
|
overrides.schemaWritable === undefined
|
|
666
667
|
) {
|
|
667
668
|
merged.schemaWritable = true
|
|
@@ -670,7 +671,7 @@ export function loadConfig(
|
|
|
670
671
|
// them would not either. An explicit setting still wins.
|
|
671
672
|
if (
|
|
672
673
|
merged.schemaStore &&
|
|
673
|
-
|
|
674
|
+
setting('CROMBOLO_RUNTIME_INSTALLS') === undefined &&
|
|
674
675
|
overrides.runtimeInstalls === undefined
|
|
675
676
|
) {
|
|
676
677
|
merged.runtimeInstalls = false
|
|
@@ -727,7 +728,7 @@ function stripUndefined<T extends object>(value: T): Partial<T> {
|
|
|
727
728
|
*/
|
|
728
729
|
export function describeDatabase(
|
|
729
730
|
config: Pick<CromboloConfig, 'dialect' | 'sqliteFile'>,
|
|
730
|
-
url: string | undefined =
|
|
731
|
+
url: string | undefined = setting('CROMBOLO_POSTGRES_URL') ?? setting('DATABASE_URL'),
|
|
731
732
|
): string {
|
|
732
733
|
if (config.dialect !== 'postgres') return config.sqliteFile
|
|
733
734
|
if (!url) return 'postgres'
|
|
@@ -739,4 +740,4 @@ export function describeDatabase(
|
|
|
739
740
|
}
|
|
740
741
|
}
|
|
741
742
|
|
|
742
|
-
export const VERSION = '0.
|
|
743
|
+
export const VERSION = '0.19.0'
|
package/src/email-ses.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
postToProvider,
|
|
31
31
|
validateMessage,
|
|
32
32
|
} from './email.ts'
|
|
33
|
+
import { setting } from './settings.ts'
|
|
33
34
|
|
|
34
35
|
export interface SesOptions extends EmailAdapterOptions {
|
|
35
36
|
region: string
|
|
@@ -228,13 +229,13 @@ export function rawMime(
|
|
|
228
229
|
|
|
229
230
|
export function sesEmail(options: SesOptions): EmailPort {
|
|
230
231
|
if (!options.region) throw new Error('An SES e-mail adapter needs a region.')
|
|
231
|
-
const accessKeyId = options.accessKeyId ??
|
|
232
|
-
const secretAccessKey = options.secretAccessKey ??
|
|
232
|
+
const accessKeyId = options.accessKeyId ?? setting('AWS_ACCESS_KEY_ID') ?? ''
|
|
233
|
+
const secretAccessKey = options.secretAccessKey ?? setting('AWS_SECRET_ACCESS_KEY') ?? ''
|
|
233
234
|
if (!accessKeyId || !secretAccessKey)
|
|
234
235
|
throw new Error(
|
|
235
236
|
'An SES e-mail adapter needs credentials: pass accessKeyId and secretAccessKey, or set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Instance roles are not resolved.',
|
|
236
237
|
)
|
|
237
|
-
const sessionToken = options.sessionToken ??
|
|
238
|
+
const sessionToken = options.sessionToken ?? setting('AWS_SESSION_TOKEN') ?? undefined
|
|
238
239
|
const call = options.fetch ?? fetch
|
|
239
240
|
const base = options.endpoint ?? `https://email.${options.region}.amazonaws.com`
|
|
240
241
|
assertSecureEndpoint(base, 'SES')
|
package/src/index.ts
CHANGED
package/src/member-auth.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
expireCookie,
|
|
27
27
|
hashPassword,
|
|
28
28
|
isNativeHash,
|
|
29
|
+
isSameOrigin,
|
|
29
30
|
memberCookieName,
|
|
30
31
|
passwordConfigJson,
|
|
31
32
|
readCookie,
|
|
@@ -125,30 +126,6 @@ async function readInput(request: Request): Promise<Record<string, string>> {
|
|
|
125
126
|
*/
|
|
126
127
|
const safeReturnUrl = (value: string | undefined): string | undefined => localReturnUrl(value)
|
|
127
128
|
|
|
128
|
-
/**
|
|
129
|
-
* Whether a POST came from this site, rather than a form on someone else's.
|
|
130
|
-
*
|
|
131
|
-
* These three endpoints take a plain form post and act on the member cookie, and
|
|
132
|
-
* `SameSite=Lax` does not cover a cross-site POST's effect here: an attacker's
|
|
133
|
-
* form can sign a visitor into an account the attacker controls, or out of their
|
|
134
|
-
* own. Umbraco's surface controllers carry an antiforgery token for this; with no
|
|
135
|
-
* token to hand, the fetch metadata a browser sends is what distinguishes them.
|
|
136
|
-
*
|
|
137
|
-
* A request with neither header is allowed: that is a non-browser client, which
|
|
138
|
-
* carries no ambient cookies to abuse.
|
|
139
|
-
*/
|
|
140
|
-
function fromThisSite(request: Request): boolean {
|
|
141
|
-
const site = request.headers.get('sec-fetch-site')
|
|
142
|
-
if (site) return site === 'same-origin' || site === 'none'
|
|
143
|
-
const origin = request.headers.get('origin')
|
|
144
|
-
if (!origin) return true
|
|
145
|
-
try {
|
|
146
|
-
return origin === new URL(request.url).origin
|
|
147
|
-
} catch {
|
|
148
|
-
return false
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
129
|
export function createMemberAuth(
|
|
153
130
|
db: Db,
|
|
154
131
|
config: CromboloConfig,
|
|
@@ -468,7 +445,8 @@ export function createMemberAuth(
|
|
|
468
445
|
})
|
|
469
446
|
}
|
|
470
447
|
if (request.method !== 'POST') return new Response(null, { status: 405 })
|
|
471
|
-
if (!
|
|
448
|
+
if (!isSameOrigin(request, config.applicationUrl || undefined))
|
|
449
|
+
return new Response('Forbidden', { status: 403 })
|
|
472
450
|
const input = await readInput(request)
|
|
473
451
|
switch (step) {
|
|
474
452
|
case 'setup': {
|
|
@@ -603,7 +581,10 @@ export function createMemberAuth(
|
|
|
603
581
|
if (action === '2fa' || action.startsWith('2fa/'))
|
|
604
582
|
return manageTwoFactor(request, action.slice(4))
|
|
605
583
|
if (request.method !== 'POST') return new Response(null, { status: 405 })
|
|
606
|
-
|
|
584
|
+
// SameSite=Lax still lets a sibling subdomain post here, signing a visitor
|
|
585
|
+
// into an account the attacker holds, or out of their own.
|
|
586
|
+
if (!isSameOrigin(request, config.applicationUrl || undefined))
|
|
587
|
+
return new Response('Forbidden', { status: 403 })
|
|
607
588
|
switch (action) {
|
|
608
589
|
case 'login':
|
|
609
590
|
return login(request)
|
package/src/ports.ts
CHANGED
|
@@ -699,7 +699,11 @@ function userTwoFactorPort(service: TwoFactorService): UserTwoFactorPort {
|
|
|
699
699
|
const enabled = await service.enable(userKey, provider, secret, code)
|
|
700
700
|
return enabled.ok
|
|
701
701
|
? { ok: true, recoveryCodes: enabled.value.recoveryCodes }
|
|
702
|
-
: {
|
|
702
|
+
: {
|
|
703
|
+
ok: false,
|
|
704
|
+
message: enabled.message,
|
|
705
|
+
alreadyEnabled: enabled.reason === 'alreadyEnabled',
|
|
706
|
+
}
|
|
703
707
|
},
|
|
704
708
|
async disable(userKey, code) {
|
|
705
709
|
const disabled = await service.disable(userKey, provider, code)
|
package/src/seo.ts
CHANGED
|
@@ -155,8 +155,8 @@ export interface SeoHostOptions {
|
|
|
155
155
|
cache: PublishedCache
|
|
156
156
|
/** Whether a visitor who is not signed in would be turned away from a page. */
|
|
157
157
|
isProtected(content: PublishedContent): Promise<boolean>
|
|
158
|
-
/** A document's latest saved version, as the preview renders it. */
|
|
159
|
-
draft(key: string, culture: string | null): Promise<DraftModel | undefined>
|
|
158
|
+
/** A document's latest saved version, as the preview renders it, if `principal` may read it. */
|
|
159
|
+
draft(key: string, culture: string | null, principal: Principal): Promise<DraftModel | undefined>
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
export interface SeoHost {
|
|
@@ -311,11 +311,11 @@ export function createSeoHost(options: SeoHostOptions): SeoHost {
|
|
|
311
311
|
return false
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
const preview = async (request: Request): Promise<Response> => {
|
|
314
|
+
const preview = async (request: Request, principal: Principal): Promise<Response> => {
|
|
315
315
|
const url = new URL(request.url)
|
|
316
316
|
const key = url.searchParams.get('document') ?? ''
|
|
317
317
|
if (!UUID.test(key)) return Response.json({ message: 'Choose a page.' }, { status: 400 })
|
|
318
|
-
const draft = await options.draft(key, url.searchParams.get('culture') || null)
|
|
318
|
+
const draft = await options.draft(key, url.searchParams.get('culture') || null, principal)
|
|
319
319
|
if (!draft) return Response.json({ message: 'That page could not be found.' }, { status: 404 })
|
|
320
320
|
const origin = originOf(request, config)
|
|
321
321
|
const snapshot = await cache.snapshot()
|
|
@@ -338,7 +338,7 @@ export function createSeoHost(options: SeoHostOptions): SeoHost {
|
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
const handle: SeoHost['handle'] = async (request, subpath, principal) => {
|
|
341
|
-
if (subpath === '/preview' && request.method === 'GET') return preview(request)
|
|
341
|
+
if (subpath === '/preview' && request.method === 'GET') return preview(request, principal)
|
|
342
342
|
if (subpath !== '/settings') return undefined
|
|
343
343
|
if (!hasSection(principal, 'settings')) return new Response('Forbidden', { status: 403 })
|
|
344
344
|
if (request.method === 'GET') return Response.json(await settings())
|
package/src/server.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { join } from 'node:path'
|
|
|
11
11
|
import { createDeliveryApi, resolveDeliveryApiSettings } from '@crombolo/api-delivery'
|
|
12
12
|
import {
|
|
13
13
|
type ClientAddress,
|
|
14
|
+
canReadDocument,
|
|
14
15
|
createManagementApiRouter,
|
|
15
16
|
hasSection,
|
|
16
17
|
type Principal,
|
|
@@ -21,6 +22,8 @@ import {
|
|
|
21
22
|
cookieNames,
|
|
22
23
|
createAuthRoutes,
|
|
23
24
|
expireCookie,
|
|
25
|
+
isSafeMethod,
|
|
26
|
+
isSameOrigin,
|
|
24
27
|
REDACTED,
|
|
25
28
|
readCookie,
|
|
26
29
|
serializeCookie,
|
|
@@ -371,6 +374,8 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
371
374
|
backOfficePath: paths.backOfficePath,
|
|
372
375
|
service: auth,
|
|
373
376
|
cookies,
|
|
377
|
+
applicationUrl: config.applicationUrl || undefined,
|
|
378
|
+
allowLocalLogin: config.allowLocalLogin,
|
|
374
379
|
twoFactor: {
|
|
375
380
|
providersFor: (userKey) => twoFactor.providers(userKey),
|
|
376
381
|
verify: (userKey, provider, code) =>
|
|
@@ -448,8 +453,22 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
448
453
|
async function authenticate(request: Request): Promise<Principal | undefined> {
|
|
449
454
|
const header = request.headers.get('authorization')
|
|
450
455
|
const bearer = header?.toLowerCase().startsWith('bearer ') ? header.slice(7).trim() : undefined
|
|
451
|
-
const
|
|
456
|
+
const fromCookie = !bearer || bearer === REDACTED
|
|
457
|
+
const token = fromCookie ? readCookie(request, names.accessToken) : bearer
|
|
452
458
|
if (!token) return undefined
|
|
459
|
+
// The browser sends the cookie wherever the request came from, so a write
|
|
460
|
+
// that relies on it must come from this site; a real bearer token need not.
|
|
461
|
+
if (
|
|
462
|
+
fromCookie &&
|
|
463
|
+
!isSafeMethod(request.method) &&
|
|
464
|
+
!isSameOrigin(request, config.applicationUrl || undefined)
|
|
465
|
+
) {
|
|
466
|
+
log.warning('Refused a signed-in {method} {path} from another site', {
|
|
467
|
+
method: request.method,
|
|
468
|
+
path: new URL(request.url).pathname,
|
|
469
|
+
})
|
|
470
|
+
return undefined
|
|
471
|
+
}
|
|
453
472
|
|
|
454
473
|
const identity = await auth.resolveAccessToken(token)
|
|
455
474
|
if (!identity) return undefined
|
|
@@ -695,8 +714,14 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
695
714
|
search: (term, options) => new SiteSearch(db).query(term, options),
|
|
696
715
|
})
|
|
697
716
|
|
|
698
|
-
|
|
699
|
-
|
|
717
|
+
const nodeLookup = createNodeLookup(db)
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* A document's latest saved version, as preview shows it, in the published
|
|
721
|
+
* tree's context — or undefined when `principal` may not read it.
|
|
722
|
+
*/
|
|
723
|
+
async function draftModel(key: string, requested: string | null, principal: Principal) {
|
|
724
|
+
if (!(await canReadDocument(principal, key, nodeLookup))) return undefined
|
|
700
725
|
const draft = await loadDraftNode(db, key, {
|
|
701
726
|
nodeState: schema.nodeState,
|
|
702
727
|
nodeId: schema.nodeId,
|
|
@@ -803,7 +828,7 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
803
828
|
const api = createManagementApiRouter({
|
|
804
829
|
deps: managementDeps,
|
|
805
830
|
authenticate,
|
|
806
|
-
nodes:
|
|
831
|
+
nodes: nodeLookup,
|
|
807
832
|
allowLocalLogin: config.allowLocalLogin,
|
|
808
833
|
audit: createAuditSink(db),
|
|
809
834
|
clientAddress,
|
|
@@ -1929,13 +1954,15 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
1929
1954
|
* draft of the page it resolves to.
|
|
1930
1955
|
*/
|
|
1931
1956
|
async function renderPreview(request: Request, pathname: string, host: string) {
|
|
1932
|
-
if (!readCookie(request, PREVIEW_COOKIE)
|
|
1957
|
+
if (!readCookie(request, PREVIEW_COOKIE)) return undefined
|
|
1958
|
+
const principal = await authenticate(request)
|
|
1959
|
+
if (!principal) return undefined
|
|
1933
1960
|
const byKey = /^\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/?$/i.exec(
|
|
1934
1961
|
pathname,
|
|
1935
1962
|
)
|
|
1936
1963
|
const key = byKey?.[1] ?? (await cache.resolve(host, pathname))?.content.key
|
|
1937
1964
|
if (!key) return undefined
|
|
1938
|
-
const draft = await draftModel(key, new URL(request.url).searchParams.get('culture'))
|
|
1965
|
+
const draft = await draftModel(key, new URL(request.url).searchParams.get('culture'), principal)
|
|
1939
1966
|
if (!draft) return undefined
|
|
1940
1967
|
return renderer.renderModel(draft.content, draft.culture, {
|
|
1941
1968
|
...(await pageRequest(request)),
|