@crombolo/server 0.20.0 → 0.21.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/server",
3
- "version": "0.20.0",
3
+ "version": "0.21.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.20.0",
34
- "@crombolo/api-management": "0.20.0",
35
- "@crombolo/assistant": "0.20.0",
36
- "@crombolo/auth": "0.20.0",
37
- "@crombolo/backoffice-host": "0.20.0",
38
- "@crombolo/contracts": "0.20.0",
39
- "@crombolo/core": "0.20.0",
40
- "@crombolo/data": "0.20.0",
41
- "@crombolo/render": "0.20.0",
42
- "@crombolo/schema": "0.20.0",
43
- "@crombolo/transfer": "0.20.0",
33
+ "@crombolo/api-delivery": "0.21.0",
34
+ "@crombolo/api-management": "0.21.0",
35
+ "@crombolo/assistant": "0.21.0",
36
+ "@crombolo/auth": "0.21.0",
37
+ "@crombolo/backoffice-host": "0.21.0",
38
+ "@crombolo/contracts": "0.21.0",
39
+ "@crombolo/core": "0.21.0",
40
+ "@crombolo/data": "0.21.0",
41
+ "@crombolo/render": "0.21.0",
42
+ "@crombolo/schema": "0.21.0",
43
+ "@crombolo/transfer": "0.21.0",
44
44
  "@logtape/logtape": "^2.3.8"
45
45
  }
46
46
  }
@@ -116,6 +116,7 @@ export function createDocumentPort(
116
116
  return {
117
117
  byKey: (key) => repo.byKey(key),
118
118
  propertyAliases: (key) => repo.propertyAliases(key),
119
+ propertyTypes: (key) => repo.propertyTypeKeys(key),
119
120
  byKeyPublished: (key) => repo.byKeyPublished(key),
120
121
  validate: (input, cultures) => repo.validate(input, cultures),
121
122
 
@@ -608,17 +608,15 @@ export function createUserPorts(
608
608
 
609
609
  async permissions(principal, tree, keys) {
610
610
  if (tree !== 'document') {
611
- // Media carries no verbs; element verbs are the groups' own until the Library exists
612
- const verbs =
613
- tree === 'element'
614
- ? [
615
- ...new Set(
616
- principal.groups.flatMap((g) =>
617
- g.defaults.filter((p) => p.startsWith('Umb.Element')),
618
- ),
619
- ),
620
- ]
621
- : []
611
+ // Media and element verbs are the groups' own: neither has per-node permissions
612
+ const prefixes = tree === 'element' ? ['Umb.Element'] : ['Crombolo.Media.']
613
+ const verbs = [
614
+ ...new Set(
615
+ principal.groups.flatMap((g) =>
616
+ g.defaults.filter((p) => prefixes.some((prefix) => p.startsWith(prefix))),
617
+ ),
618
+ ),
619
+ ]
622
620
  return keys.map((nodeKey) => ({ nodeKey: normaliseUuid(nodeKey), permissions: verbs }))
623
621
  }
624
622
  const found = await nodes.documents(keys)
package/src/approvals.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  approvalsNeeded,
15
15
  DocumentPermissions,
16
16
  descendantStages,
17
+ hasPathAccess,
17
18
  normaliseUuid,
18
19
  permissionsForPath,
19
20
  type SchemaWorkflow,
@@ -80,6 +81,7 @@ interface PageFacts {
80
81
  key: string
81
82
  name: string
82
83
  chain: string[]
84
+ trashed: boolean
83
85
  contentTypeAlias: string | undefined
84
86
  variesByCulture: boolean
85
87
  }
@@ -273,6 +275,7 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
273
275
  key: node.key,
274
276
  name: node.text ?? node.key,
275
277
  chain: ids.flatMap((id) => keyOf.get(id) ?? []),
278
+ trashed: node.trashed,
276
279
  contentTypeAlias: type[0]?.alias,
277
280
  // Umbraco's flags: 1 is culture, 2 is segment.
278
281
  variesByCulture: (Number(type[0]?.variations ?? 0) & 1) === 1,
@@ -295,6 +298,19 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
295
298
  action === 'publish' ? DocumentPermissions.Publish : DocumentPermissions.Unpublish,
296
299
  )
297
300
 
301
+ /**
302
+ * Refuses, with a 403, a caller who cannot reach the page through their start
303
+ * nodes or lacks a verb on it: asking about a page needs what opening it does.
304
+ */
305
+ const assertMayReach = (principal: Principal, facts: PageFacts, verbs: readonly string[]) => {
306
+ const granted = permissionsForPath(principal.groups, facts.chain)
307
+ if (
308
+ !hasPathAccess(principal.startNodes.document, facts.chain, facts.trashed) ||
309
+ !verbs.every((verb) => granted.has(verb))
310
+ )
311
+ throw new ApprovalRefused('You do not have access to this page.', 403)
312
+ }
313
+
298
314
  const covers = (workflow: SchemaWorkflow | undefined, action: ApprovalAction) =>
299
315
  workflow !== undefined && (action === 'publish' || workflow.unpublish)
300
316
 
@@ -749,6 +765,7 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
749
765
  key: '',
750
766
  name: 'This page',
751
767
  chain: parent?.chain ?? [],
768
+ trashed: false,
752
769
  contentTypeAlias: type[0]?.alias,
753
770
  variesByCulture: false,
754
771
  }
@@ -800,6 +817,7 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
800
817
  async send(principal, key, action, cultures, comment, schedule) {
801
818
  const facts = await page(key)
802
819
  if (!facts) throw new ApprovalRefused('The page could not be found.', 404)
820
+ assertMayReach(principal, facts, [DocumentPermissions.Read, DocumentPermissions.Update])
803
821
  const workflow = await covering(facts)
804
822
  if (!workflow || !covers(workflow, action))
805
823
  throw new ApprovalRefused(
@@ -1064,6 +1082,7 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
1064
1082
  async forPage(principal, key) {
1065
1083
  const facts = await page(key)
1066
1084
  if (!facts) throw new ApprovalRefused('The page could not be found.', 404)
1085
+ assertMayReach(principal, facts, [DocumentPermissions.Read])
1067
1086
  const workflow = await covering(facts)
1068
1087
  const all = await requests().forNode(key)
1069
1088
  const waiting = all.find((r) => r.state === 'waiting' || r.state === 'scheduled')
package/src/config.ts CHANGED
@@ -740,4 +740,4 @@ export function describeDatabase(
740
740
  }
741
741
  }
742
742
 
743
- export const VERSION = '0.20.0'
743
+ export const VERSION = '0.21.0'
@@ -26,6 +26,7 @@ import {
26
26
  externalLoginProvider,
27
27
  } from '@crombolo/data'
28
28
  import type { IdentityProvider } from './identity-providers.ts'
29
+ import { originOf } from './seo.ts'
29
30
 
30
31
  /** A member or user, as far as signing in is concerned. */
31
32
  export interface ExternalAccount {
@@ -155,10 +156,13 @@ export function createExternalSignIn(
155
156
  return key
156
157
  }
157
158
  const flowCookie = `crombolo-external-${audience.audience}`
158
- const originOf = (request: Request) =>
159
- (options.applicationUrl || new URL(request.url).origin).replace(/\/$/, '')
159
+ // The address the visitor used, as a proxy in front says it, so a site
160
+ // reached by several names signs in on the one it was opened on. The
161
+ // provider still refuses a callback it was not registered with.
162
+ const callbackOrigin = (request: Request) =>
163
+ originOf(request, { applicationUrl: options.applicationUrl })
160
164
  const callbackUrl = (request: Request, id: string) =>
161
- `${originOf(request)}${audience.basePath}/${id}/callback`
165
+ `${callbackOrigin(request)}${audience.basePath}/${id}/callback`
162
166
  const redirect = (location: string, cookies: string[] = []) => {
163
167
  const headers = new Headers({ location })
164
168
  for (const cookie of cookies) headers.append('set-cookie', cookie)