Skip to content

Commit eb9b237

Browse files
committed
fix(spec): push route is the inbox actionUrl the shell resolves; path refusals
Delta contract review round 3 on the push device registry spec. - PushDeliveryData.route is the notification's actionUrl, the same value the inbox serves: app-relative (/OBJECT/ID) or already /apps/... The describes and the docblock say the shell resolves it on tap exactly as the bell and Home do (resolveNotificationTarget with its host app segment) and never navigates it verbatim. - The docblock says where the data sits per vendor: FCM message.data, APNs top level beside aps, never under a data key. - PushRouteSchema refuses dot segments and percent-encoded /, \ and . in its path, as a pattern the published JSON Schema carries too. - The device docblock and registerDevice say a token the user already holds under another deviceId refreshes that row, never a second live row. - The changeset follows. Claude-Session: https://claude.ai/code/session_01ADHkmT6K7dHh79Lej3sWr5 Co-authored-by: Claude <noreply@anthropic.com>
1 parent e7b06bc commit eb9b237

7 files changed

Lines changed: 127 additions & 56 deletions

File tree

‎.changeset/29067-push-device-registry-spec.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Metadata-protocol: added
1010
Nothing here is served or read yet. Every new or touched schema carries a `[PLANNED — not yet served]` or `[PLANNED — not yet read]` marker in its description, and no route row is added: the device routes land in `DEFAULT_NOTIFICATION_ROUTES` together with their handlers, so the catalog never advertises a route that answers 404. Nothing a client or an operator writes today is refused.
1111

1212
- **`RegisterDeviceRequestSchema`** gains three optional members: `vendor` (`apns` | `fcm`; absent, the server derives it from `platform`, `ios` → `apns` and `android` → `fcm`, and a `web` registration names `apns` or `fcm`), `appId` and `locale` (a BCP 47 tag, the house `LocaleSchema`). `token`, `platform`, `deviceId` and `name` are unchanged, so every body a client sent before still parses as it did. The describes now say that re-registering a `deviceId` refreshes that device, and that a request without one gets a server-minted id the client keeps. A `vendor` outside `apns` / `fcm` is refused; since the member is new, no body sent before carries one. `RegisterDeviceResponseSchema` and `UnregisterDevice*` keep their members and gain only their description.
13-
- **`UserDeviceSchema`** (new, `system/push-device.zod.ts`) is the stored device: `deviceId`, `userId`, `vendor`, `token`, `platform`, `enabled`, and optional `appId`, `locale`, `name`, `invalidatedAt` and `lastSeenAt`. A device belongs to its user alone (no organization member), a token has one live owner (a second user's registration takes it over), and a token the vendor reports dead keeps its row with `enabled: false` and `invalidatedAt`.
13+
- **`UserDeviceSchema`** (new, `system/push-device.zod.ts`) is the stored device: `deviceId`, `userId`, `vendor`, `token`, `platform`, `enabled`, and optional `appId`, `locale`, `name`, `invalidatedAt` and `lastSeenAt`. A device belongs to its user alone (no organization member), a token has one live row (the same user's registration without a `deviceId` refreshes the row that holds it, and a second user's registration takes it over), and a token the vendor reports dead keeps its row with `enabled: false` and `invalidatedAt`.
1414
- **`INotificationService`** gains four optional members: `registerDevice(userId, request)`, `unregisterDevice(userId, deviceId)`, `listDevices(userId)` and `invalidateDeviceToken(token)`. Their docs state the semantics an implementation owes. Absence means the capability is unavailable, so every existing implementation stays valid.
15-
- **`PushDeliveryDataSchema`** (new, `api/push-delivery.zod.ts`) is the data a push carries to the shell: `notificationId` and an optional `route`. `PushRouteSchema` admits only a same-server relative path (one leading `/`; no scheme, host, backslash, whitespace or control character). The route is derived, never authored: it is the notification's existing `actionUrl` when that passes the schema, and absent otherwise. No `notify` key is added.
15+
- **`PushDeliveryDataSchema`** (new, `api/push-delivery.zod.ts`) is the data a push carries to the shell: `notificationId` and an optional `route`. `PushRouteSchema` admits only a same-server relative path (one leading `/`; no scheme, host, backslash, whitespace or control character; no dot segment and no percent-encoded `/`, `\` or `.` in its path). The route is derived, never authored: it is the notification's existing `actionUrl` (app-relative `/OBJECT/ID` or an `/apps/…` route) when that passes the schema, and absent otherwise. The shell resolves it on tap as the inbox does, never verbatim. FCM carries this data in `message.data`; APNs at the top level of the payload, beside `aps`. No `notify` key is added.
1616
- **`PushServiceConfigSchema`** (new, `system/push-config.zod.ts`, beside the email transport configuration): an `apns` block (token auth: `teamId`, `keyId`, `topic`, `environment: sandbox | production`, the `.p8` key by `credentialRef`) and an `fcm` block (HTTP v1: `projectId`, the service-account JSON by `credentialRef`). Secrets are references only (ADR-0143 D3). An inline secret is refused by name under the keys an operator would reach for, and refused as the content of a reference (a PEM block or a JSON document). `PushVendorSchema` names the two vendors. It is not a stack-definition key until its reader ships.

‎content/docs/references/api/push-delivery.mdx‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,40 @@ description: "Push delivery data — what a push carries to the shell. Reference
66

77
{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */}
88

9-
Push delivery data — what a push carries to the shell (ADR-0012 §8: the
10-
`data` member of the push channel's rendered body).
9+
Push delivery data — what a push carries to the shell.
1110

1211
The shell reads it when the user taps the push: `notificationId` names the
1312
notification (the same id the inbox lists and `markRead` takes), and
14-
`route` is the Console path the shell opens.
13+
`route` is the notification's `actionUrl`, the link the inbox serves for it.
14+
15+
**Where it sits in the vendor payload.** ADR-0012 §8 names it the `data`
16+
member of the push renderer's output; that is the renderer's shape, not the
17+
vendor payload. On FCM (HTTP v1) these members go in `message.data`, a map
18+
of string values. On APNs they sit at the top level of the payload, beside
19+
`aps`, and never under a `data` key.
1520

1621
**Declared ahead of its producer.** No push channel delivers yet, so
1722
nothing produces this data today; `PushDeliveryDataSchema` carries a
1823
`[PLANNED — not yet served]` marker in its `.describe()` until the push
1924
channel ships. The route rule below is the contract that channel owes.
2025

21-
**Where `route` comes from — derived, never authored.** There is no
22-
`notify` key for it. It is the notification's existing `actionUrl`, the
23-
value the inbox already serves: an explicit `url` / `actionUrl` in the
24-
notification's payload, else `/OBJECT/ID` built from the notification's
25-
source record, else none. When that value passes `PushRouteSchema`
26-
the push carries it as `route`; when it does not (an absolute URL to
27-
another site, say) or there is none, the push carries no `route` and the
28-
tap opens the shell's default screen. The delivery is never failed for it.
26+
**What `route` is — the inbox's `actionUrl`, derived, never authored.**
27+
There is no `notify` key for it. It is the value the inbox already serves:
28+
an explicit `url` / `actionUrl` in the notification's payload, else
29+
`/OBJECT/ID` built from the notification's source record, else none. So it
30+
is either app-relative (`/opportunity/123`) or already a Console route
31+
(`/apps/crm/opportunity/123`). When that value passes
32+
`PushRouteSchema` the push carries it as `route`; when it does not
33+
(an absolute URL to another site, say) or there is none, the push carries
34+
no `route` and the tap opens the shell's default screen. The delivery is
35+
never failed for it.
36+
37+
**The shell never navigates it verbatim.** On tap it resolves `route`
38+
exactly as the inbox bell and Home do for the same notification: through
39+
`resolveNotificationTarget` (`ui/packages/app-shell/src/utils/appRoute.ts`)
40+
with its host app segment, which hosts an app-relative path under
41+
`/apps/APP/` and passes an `/apps/…` route through. One resolver, so a
42+
push and the inbox row open the same screen.
2943

3044
Not to be confused with the `PushNotificationSchema` that `system/` once
3145
declared and then removed (ADR-0049): that was an authoring template shape;
@@ -49,23 +63,21 @@ const result = PushDeliveryDataSchema.parse(data);
4963

5064
## PushDeliveryData
5165

52-
[PLANNED — not yet served] The data a push delivery carries to the shell: the notification id and the same-server route opened on tap. No push channel delivers yet
66+
[PLANNED — not yet served] The data a push delivery carries to the shell: the notification id and its actionUrl as a same-server route. No push channel delivers yet
5367

5468
### Properties
5569

5670
| Property | Type | Required | Description |
5771
| :--- | :--- | :--- | :--- |
5872
| **notificationId** | `string` | ✅ | Notification id — the one the inbox lists and markRead takes |
59-
| **route** | `string` | optional | Console route opened on tap: the notification actionUrl when it is a same-server relative path, absent otherwise |
73+
| **route** | `string` | optional | The notification actionUrl, the value the inbox serves, when it is a same-server relative path; absent otherwise. The shell resolves it on tap as the inbox bell and Home do, never verbatim |
6074

6175

6276
---
6377

6478
## PushRoute
6579

66-
Same-server relative path the shell opens on tap (for example /apps/crm/opportunity/123); never an absolute or off-server URL
67-
68-
**Type:** `string`
80+
The notification actionUrl as a same-server relative path: app-relative (/opportunity/123) or a Console route (/apps/crm/opportunity/123). The shell resolves it on tap as the inbox does, never verbatim; never an absolute or off-server URL
6981

7082

7183
---

‎content/docs/references/system/push-device.mdx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ Three rules the registry owes, stated here because they decide the shape:
2626
person's notifications whichever organization they come from; the
2727
organization travels on the notification, never on the device. The
2828
identity of a row is (`userId`, `deviceId`).
29-
- **(b) One live owner per token.** A vendor token is delivered to one user
30-
only. When a second user registers a token another user's device holds,
31-
the token moves to the second user and the first user's row for it is
29+
- **(b) One live row per token.** A vendor token is delivered to one row
30+
only. A token this user already holds under another `deviceId` (the app's
31+
storage was cleared, so the registration carries no `deviceId`) refreshes
32+
that row and answers its `deviceId`; it never makes a second live row.
33+
When a second user registers a token another user's device holds, the
34+
token moves to the second user and the first user's row for it is
3235
removed, so a push meant for the phone's previous user never reaches its
3336
new one.
3437
- **(c) A dead token keeps its row.** When the vendor reports a token dead

‎packages/spec/src/api/push-delivery.test.ts‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22
//
3-
// The data a push delivery carries to the shell. Its `route` is opened by the
4-
// shell on tap, so the contract admits only a same-server relative path: a
5-
// value that could navigate anywhere else (another origin, a scheme, a
6-
// protocol-relative reference, or a path a URL parser rewrites into one) is
7-
// refused here, and the server leaves `route` out instead of sending it.
3+
// The data a push delivery carries to the shell. Its `route` is the
4+
// notification's actionUrl, which the shell resolves on tap as the inbox does,
5+
// so the contract admits only a same-server relative path: a value that could
6+
// navigate anywhere else (another origin, a scheme, a protocol-relative
7+
// reference, a path a URL parser rewrites into one, or a path a router would
8+
// normalise or decode elsewhere) is refused here, and the server leaves
9+
// `route` out instead of sending it.
810

911
import { describe, it, expect } from 'vitest';
1012
import { PushDeliveryDataSchema, PushRouteSchema } from './push-delivery.zod';
1113

1214
describe('PushDeliveryDataSchema', () => {
13-
it('accepts a notification id with a Console route', () => {
14-
const data = { notificationId: 'ntf_1', route: '/apps/crm/opportunity/123' };
15+
// The two shapes the inbox serves as actionUrl: app-relative (the shell
16+
// hosts it under its app) and a route already addressed to an app.
17+
it.each(['/opportunity/123', '/apps/crm/opportunity/123'])('accepts the inbox actionUrl %j as route', (route) => {
18+
const data = { notificationId: 'ntf_1', route };
1519
expect(PushDeliveryDataSchema.parse(data)).toEqual(data);
1620
});
1721

@@ -25,6 +29,13 @@ describe('PushDeliveryDataSchema', () => {
2529
expect(PushRouteSchema.safeParse('/').success).toBe(true);
2630
});
2731

32+
it.each(['/apps/crm/.well-known', '/apps/crm/...', '/apps/crm/x?next=%2Fapps%2Fcrm', '/apps/crm/x#%2e%2e'])(
33+
'accepts %j: no dot segment, and a query or fragment keeps its own encoding',
34+
(route) => {
35+
expect(PushRouteSchema.safeParse(route).success).toBe(true);
36+
},
37+
);
38+
2839
it('requires a notification id', () => {
2940
const parsed = PushDeliveryDataSchema.safeParse({ route: '/x' });
3041
expect(parsed.success).toBe(false);
@@ -43,6 +54,15 @@ describe('PushDeliveryDataSchema', () => {
4354
'/\t/evil.example',
4455
'/\n/evil.example',
4556
'/apps/crm\\..\\x',
57+
// A router that normalises or decodes the path would open somewhere else.
58+
'/../../api/v1/me',
59+
'/%2e%2e/x',
60+
'/./x',
61+
'/a%2fb',
62+
'/a%5cb',
63+
'/apps/crm/..',
64+
'/a%2Fb',
65+
'/apps/crm/./x?tab=notes',
4666
])('refuses route %j', (route) => {
4767
const parsed = PushDeliveryDataSchema.safeParse({ notificationId: 'ntf_1', route });
4868
expect(parsed.success).toBe(false);

‎packages/spec/src/api/push-delivery.zod.ts‎

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,85 @@ import { z } from 'zod';
44
import { lazySchema } from '../shared/lazy-schema';
55

66
/**
7-
* Push delivery data — what a push carries to the shell (ADR-0012 §8: the
8-
* `data` member of the push channel's rendered body).
7+
* Push delivery data — what a push carries to the shell.
98
*
109
* The shell reads it when the user taps the push: `notificationId` names the
1110
* notification (the same id the inbox lists and `markRead` takes), and
12-
* `route` is the Console path the shell opens.
11+
* `route` is the notification's `actionUrl`, the link the inbox serves for it.
12+
*
13+
* **Where it sits in the vendor payload.** ADR-0012 §8 names it the `data`
14+
* member of the push renderer's output; that is the renderer's shape, not the
15+
* vendor payload. On FCM (HTTP v1) these members go in `message.data`, a map
16+
* of string values. On APNs they sit at the top level of the payload, beside
17+
* `aps`, and never under a `data` key.
1318
*
1419
* **Declared ahead of its producer.** No push channel delivers yet, so
1520
* nothing produces this data today; {@link PushDeliveryDataSchema} carries a
1621
* `[PLANNED — not yet served]` marker in its `.describe()` until the push
1722
* channel ships. The route rule below is the contract that channel owes.
1823
*
19-
* **Where `route` comes from — derived, never authored.** There is no
20-
* `notify` key for it. It is the notification's existing `actionUrl`, the
21-
* value the inbox already serves: an explicit `url` / `actionUrl` in the
22-
* notification's payload, else `/OBJECT/ID` built from the notification's
23-
* source record, else none. When that value passes {@link PushRouteSchema}
24-
* the push carries it as `route`; when it does not (an absolute URL to
25-
* another site, say) or there is none, the push carries no `route` and the
26-
* tap opens the shell's default screen. The delivery is never failed for it.
24+
* **What `route` is — the inbox's `actionUrl`, derived, never authored.**
25+
* There is no `notify` key for it. It is the value the inbox already serves:
26+
* an explicit `url` / `actionUrl` in the notification's payload, else
27+
* `/OBJECT/ID` built from the notification's source record, else none. So it
28+
* is either app-relative (`/opportunity/123`) or already a Console route
29+
* (`/apps/crm/opportunity/123`). When that value passes
30+
* {@link PushRouteSchema} the push carries it as `route`; when it does not
31+
* (an absolute URL to another site, say) or there is none, the push carries
32+
* no `route` and the tap opens the shell's default screen. The delivery is
33+
* never failed for it.
34+
*
35+
* **The shell never navigates it verbatim.** On tap it resolves `route`
36+
* exactly as the inbox bell and Home do for the same notification: through
37+
* `resolveNotificationTarget` (`ui/packages/app-shell/src/utils/appRoute.ts`)
38+
* with its host app segment, which hosts an app-relative path under
39+
* `/apps/APP/` and passes an `/apps/…` route through. One resolver, so a
40+
* push and the inbox row open the same screen.
2741
*
2842
* Not to be confused with the `PushNotificationSchema` that `system/` once
2943
* declared and then removed (ADR-0049): that was an authoring template shape;
3044
* this is the wire data of a delivery, produced by the platform.
3145
*/
3246

3347
/**
34-
* A same-server relative path the shell may open: it starts with exactly one
35-
* `/`, so it carries no scheme and no host, and it contains no backslash,
36-
* whitespace or control character — a URL parser reads `\` as `/` and strips
37-
* tab and newline, which would turn `/\host` — or `/`, a tab, then `/host` —
38-
* into a protocol-relative reference to another site.
48+
* A same-server relative path: it starts with exactly one `/`, so it carries
49+
* no scheme and no host, and it contains no backslash, whitespace or control
50+
* character — a URL parser reads `\` as `/` and strips tab and newline, which
51+
* would turn `/\host` — or `/`, a tab, then `/host` — into a
52+
* protocol-relative reference to another site.
53+
*
54+
* Its path (the part before any `?` or `#`) also carries no dot segment (`.`
55+
* or `..`) and no percent-encoded `/`, `\` or `.` (`%2F`, `%5C`, `%2E`, either
56+
* case): a router that normalises or decodes the path would move it somewhere
57+
* the notification did not point. Both rules are patterns, so the published
58+
* JSON Schema carries them too. A query or fragment keeps its own encoding.
3959
*/
4060
export const PushRouteSchema = z.string()
4161
.regex(/^\/(?![/\\])[^\s\\\x00-\x1f\x7f]*$/, {
4262
message: 'A push route is a same-server relative path: it starts with a single "/" and carries no scheme, host, '
4363
+ 'backslash, whitespace or control character.',
4464
})
45-
.describe('Same-server relative path the shell opens on tap (for example /apps/crm/opportunity/123); never an absolute or off-server URL');
65+
.regex(/^(?![^?#]*(?:\/\.\.?(?:[/?#]|$)|%(?:2[eEfF]|5[cC])))/, {
66+
message: 'A push route path carries no dot segment ("." or "..") and no percent-encoded "/", "\\" or "." '
67+
+ '(%2F, %5C, %2E): a router that normalises or decodes the path would open somewhere else.',
68+
})
69+
.describe(
70+
'The notification actionUrl as a same-server relative path: app-relative (/opportunity/123) or a Console route '
71+
+ '(/apps/crm/opportunity/123). The shell resolves it on tap as the inbox does, never verbatim; never an absolute or '
72+
+ 'off-server URL',
73+
);
4674
export type PushRoute = z.input<typeof PushRouteSchema>;
4775

4876
/** The data a push delivery carries to the shell. */
4977
// The marker comes off when the push channel (#29041) produces this data.
5078
export const PushDeliveryDataSchema = lazySchema(() => z.object({
5179
notificationId: z.string().min(1).describe('Notification id — the one the inbox lists and markRead takes'),
52-
route: PushRouteSchema.optional()
53-
.describe('Console route opened on tap: the notification actionUrl when it is a same-server relative path, absent otherwise'),
80+
route: PushRouteSchema.optional().describe(
81+
'The notification actionUrl, the value the inbox serves, when it is a same-server relative path; absent otherwise. '
82+
+ 'The shell resolves it on tap as the inbox bell and Home do, never verbatim',
83+
),
5484
}).describe(
55-
'[PLANNED — not yet served] The data a push delivery carries to the shell: the notification id and the same-server route '
56-
+ 'opened on tap. No push channel delivers yet',
85+
'[PLANNED — not yet served] The data a push delivery carries to the shell: the notification id and its actionUrl as a '
86+
+ 'same-server route. No push channel delivers yet',
5787
));
5888
export type PushDeliveryData = z.input<typeof PushDeliveryDataSchema>;

0 commit comments

Comments
 (0)