Skip to content

Commit 35b01a0

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-iobdbg
2 parents 6b220ef + a35fc66 commit 35b01a0

11 files changed

Lines changed: 792 additions & 24 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/service-analytics': patch
3+
---
4+
5+
fix(service-analytics): the refusal of an ungrouped aggregate over a record-currency amount names the home field as the remedy for a consolidated total (ADR-0144 D6)
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
- **Now.** A `sum`, `avg`, `min` or `max` over a `currencyMode: 'record'` amount that does not group by its code field is still refused `INVALID_FIELD` / 400 before anything is read, with the same code, status, member, field and object. Its message now names both remedies. For one total in the home currency, point the measure at the amount's home field: by name (`homeAmount.field`) when the host relays it, or else as "the field its `currencyConfig.homeAmount.field` names", with the declaration to add if it has none. For one row per currency, add the dimension over the code field. Before, the message named only the grouping.
11+
- **Unchanged.** A measure over the home field is no record-mode amount, so it is served unchanged: ungrouped, grouped by the code field, and as a `totals` grand total, labelled with the home currency.
12+
- **The widening.** `AnalyticsServiceConfig.sourceFieldMeta` may answer one more optional key, `homeAmountField`: the amount's `currencyConfig.homeAmount.field`, beside a `currencyField` only. `AnalyticsServicePlugin` relays it. A host that does not answer it gets the message without the field's name.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli): a connection label printed by the CLI removes a password or a credential query pair wherever the URL rules read one
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
- **One credential grammar.** The database label that `os dev`, `os start` and `os serve` print, and the migrate and resync confirms, now remove URL credentials through the same shared function the datasource read door applies (`redactUrlCredentials` from `@objectstack/spec/data`): the userinfo password, and every credential query pair judged by the shared query-pair judge and its one list of names. Wherever those rules read a credential, on every path the label takes, the label drops it. When the shared rules read more, the label follows with no edit of its own.
11+
- **Unchanged.** Every value the shared rules read no credential in prints exactly as before: `postgres://`, `libsql://` and `file:` values, values with no userinfo, a username-only userinfo, and everything the URL parser already cleaned.

‎packages/cli/src/utils/connection-display.test.ts‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
// shape leaks the credentials the DSN carries.
1313

1414
import { describe, it, expect } from 'vitest';
15+
import {
16+
CREDENTIAL_URL_QUERY_PARAM_NAMES,
17+
urlCredentialQueryParams,
18+
urlUserinfoPassword,
19+
} from '@objectstack/spec/data';
1520
import { redactConnectionUrl, describeDriverConnection, describeDriverSqliteFile } from './connection-display.js';
1621

1722
describe('redactConnectionUrl', () => {
@@ -56,6 +61,145 @@ describe('redactConnectionUrl', () => {
5661
});
5762
});
5863

64+
// The label is a print-time reader of the same question the datasource doors
65+
// answer: where does a URL carry a password? It asks the platform's ONE
66+
// userinfo grammar (`@objectstack/spec/data`) rather than keeping its own, so
67+
// the oracle below is that grammar's own password accessor.
68+
describe('redactConnectionUrl — the password rule is the shared URL grammar', () => {
69+
const PASSWORD = 'S3CRET-PW';
70+
71+
it('removes the password wherever the shared grammar reads one, with or without a literal `://`', () => {
72+
// A scheme-relative authority.
73+
expect(redactConnectionUrl(`//admin:${PASSWORD}@db.example.com:5432/app`))
74+
.toBe('//admin@db.example.com:5432/app');
75+
// A tab inside the `//`, which a URL parser deletes before it reads.
76+
expect(redactConnectionUrl(`postgres:/\t/admin:${PASSWORD}@db.example.com/app`))
77+
.toBe('postgres:/\t/admin@db.example.com/app');
78+
});
79+
80+
it('removes the password where the shared grammar reads a special scheme\'s authority without a `//`', () => {
81+
expect(redactConnectionUrl(`https:admin:${PASSWORD}@db.example.com/app`))
82+
.toBe('https:admin@db.example.com/app');
83+
expect(redactConnectionUrl(`http:/admin:${PASSWORD}@db.example.com/app`))
84+
.toBe('http:/admin@db.example.com/app');
85+
expect(redactConnectionUrl(`wss:\\admin:${PASSWORD}@db.example.com/app`))
86+
.toBe('wss:\\admin@db.example.com/app');
87+
});
88+
89+
it('removes the whole password up to the last `@` of the authority, as the shared grammar bounds it', () => {
90+
expect(redactConnectionUrl('postgres://admin:S3C@RET-PW@h1:5432,h2:5432/app'))
91+
.toBe('postgres://h1:5432,h2:5432/app');
92+
});
93+
94+
it('never prints a password the shared grammar reads, in any URL shape', () => {
95+
const shapes = [
96+
`postgres://admin:${PASSWORD}@db.example.com:5432/app`,
97+
`postgres://:${PASSWORD}@db.example.com/app`,
98+
`mysql://admin:${PASSWORD}@db.example.com:3306/app`,
99+
`libsql://admin:${PASSWORD}@app-org.turso.io?authToken=jwt`,
100+
`postgres://admin:${PASSWORD}@h1:5432,h2:5432/app`,
101+
`//admin:${PASSWORD}@db.example.com:5432/app`,
102+
`postgres:/\t/admin:${PASSWORD}@db.example.com/app`,
103+
` \npostgres://admin:${PASSWORD}@db.example.com/app`,
104+
// Special schemes without the `//`, read as a URL parser reads them.
105+
`https:admin:${PASSWORD}@db.example.com/app`,
106+
`http:/admin:${PASSWORD}@db.example.com/app`,
107+
`wss:\\admin:${PASSWORD}@db.example.com/app`,
108+
];
109+
const judged = shapes.filter((value) => urlUserinfoPassword(value) !== undefined);
110+
// Non-vacuity floor: the shared grammar reads a password in every shape
111+
// listed, so the property below is never checked over nothing.
112+
expect(judged.length).toBe(shapes.length);
113+
for (const value of judged) {
114+
expect(urlUserinfoPassword(value)).toBe(PASSWORD);
115+
expect(redactConnectionUrl(value), value).not.toContain(PASSWORD);
116+
}
117+
});
118+
119+
it('keeps its output byte for byte for every value the shared grammar reads no password in', () => {
120+
const controls: ReadonlyArray<readonly [string, string]> = [
121+
['postgres://admin@db.example.com:5432/app', 'postgres://db.example.com:5432/app'],
122+
['postgres://admin:@db.example.com/app', 'postgres://db.example.com/app'],
123+
['postgres://db.example.com:5432/app?sslmode=require', 'postgres://db.example.com:5432/app'],
124+
['postgres://admin@h1:5432,h2:5432/app', 'postgres://h1:5432,h2:5432/app'],
125+
['libsql://app-org.turso.io?authToken=secret-jwt', 'libsql://app-org.turso.io'],
126+
['https://db.example.com/app', 'https://db.example.com/app'],
127+
['file:./data/app.db', 'file:./data/app.db'],
128+
['file:///var/lib/app.db', 'file:///var/lib/app.db'],
129+
['sqlite:/var/lib/app.db', 'sqlite:/var/lib/app.db'],
130+
['//admin@db.example.com/app', '//admin@db.example.com/app'],
131+
[':memory:', ':memory:'],
132+
['(in-memory)', '(in-memory)'],
133+
];
134+
for (const [value, printed] of controls) {
135+
expect(urlUserinfoPassword(value), value).toBeUndefined();
136+
expect(redactConnectionUrl(value), value).toBe(printed);
137+
}
138+
});
139+
140+
it('keeps its output byte for byte for a password the URL parser already removed', () => {
141+
expect(redactConnectionUrl(`postgres://admin:${PASSWORD}@db.example.com:5432/app`))
142+
.toBe('postgres://db.example.com:5432/app');
143+
expect(redactConnectionUrl(`libsql://admin:${PASSWORD}@app-org.turso.io?authToken=jwt`))
144+
.toBe('libsql://app-org.turso.io');
145+
});
146+
});
147+
148+
// The query half of the same rule: a credential query pair is judged by the
149+
// shared query-pair judge and its one list of names, on every path the label
150+
// takes — a value with no `://`, the URL parser's, and the hand fallback for a
151+
// value the parser rejects.
152+
describe('redactConnectionUrl — the credential query rule is the shared query-pair judge', () => {
153+
const TOKEN = 'T0KEN-VALUE';
154+
155+
it('removes a credential query pair from a value with no `://`', () => {
156+
expect(redactConnectionUrl(`libsql:app-org.turso.io?authToken=${TOKEN}`))
157+
.toBe('libsql:app-org.turso.io');
158+
expect(redactConnectionUrl(`file:local.db?authToken=${TOKEN}&mode=ro`))
159+
.toBe('file:local.db?mode=ro');
160+
});
161+
162+
it('removes a credential query pair on the hand fallback for a value the URL parser rejects', () => {
163+
expect(redactConnectionUrl(`postgres://admin@h1:5432,h2:5432/app?password=${TOKEN}&sslmode=require`))
164+
.toBe('postgres://h1:5432,h2:5432/app?sslmode=require');
165+
});
166+
167+
it('removes a credential query pair on the URL parser path', () => {
168+
expect(redactConnectionUrl(`postgres://db.example.com/app?PASSWORD=${TOKEN}`))
169+
.toBe('postgres://db.example.com/app');
170+
expect(redactConnectionUrl(`libsql://app-org.turso.io?authToken=${TOKEN}`))
171+
.toBe('libsql://app-org.turso.io');
172+
});
173+
174+
it('never prints a credential query value the shared judge reads, on any path', () => {
175+
const shapes = [
176+
`libsql:app-org.turso.io?authToken=${TOKEN}`,
177+
`file:local.db?mode=ro&AUTHTOKEN=${TOKEN}`,
178+
`file:local.db?auth%54oken=${TOKEN}`,
179+
`postgres://admin@h1:5432,h2:5432/app?password=${TOKEN}`,
180+
`postgres://db.example.com/app?password=${TOKEN}`,
181+
`libsql://app-org.turso.io?authToken=${TOKEN}#frag`,
182+
];
183+
for (const value of shapes) {
184+
expect(urlCredentialQueryParams(value, CREDENTIAL_URL_QUERY_PARAM_NAMES), value).not.toEqual([]);
185+
expect(redactConnectionUrl(value), value).not.toContain(TOKEN);
186+
}
187+
});
188+
189+
it('keeps its output byte for byte for every value with no credential query pair', () => {
190+
const controls: ReadonlyArray<readonly [string, string]> = [
191+
['postgres://admin@h1:5432,h2:5432/app?sslmode=require', 'postgres://h1:5432,h2:5432/app?sslmode=require'],
192+
['file:local.db?mode=ro', 'file:local.db?mode=ro'],
193+
['libsql:app-org.turso.io?authToken=', 'libsql:app-org.turso.io?authToken='],
194+
['postgres://db.example.com:5432/app?sslmode=require', 'postgres://db.example.com:5432/app'],
195+
];
196+
for (const [value, printed] of controls) {
197+
expect(urlCredentialQueryParams(value, CREDENTIAL_URL_QUERY_PARAM_NAMES), value).toEqual([]);
198+
expect(redactConnectionUrl(value), value).toBe(printed);
199+
}
200+
});
201+
});
202+
59203
describe('describeDriverConnection', () => {
60204
it('reads a DSN string', () => {
61205
expect(describeDriverConnection({ client: 'pg', connection: 'postgres://u:p@host:5432/app' }))

‎packages/cli/src/utils/connection-display.ts‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,33 @@
2424
* that the driver label and the host don't already say.
2525
*/
2626

27+
import { redactUrlCredentials } from '@objectstack/spec/data';
28+
2729
/**
2830
* Strip credentials from a connection string.
2931
*
30-
* Values that aren't URLs — a sqlite path, `:memory:`, the `(in-memory)`
31-
* marker — pass through untouched, as does anything the URL parser rejects
32-
* (minus its userinfo segment). Idempotent, so a call site that can't tell
33-
* whether its input was already redacted may apply it defensively.
32+
* Credentials go first, and by the platform's ONE URL credential grammar
33+
* (`redactUrlCredentials` from `@objectstack/spec/data`, the composite the
34+
* datasource read door applies): wherever that grammar reads a userinfo
35+
* password or a credential query pair — the string judged as a URL parser
36+
* cleans it, the pair judged by the shared query-pair judge and its one list
37+
* of credential names — the label drops it, so the label cannot print a
38+
* credential the doors would refuse or redact. No second grammar and no second
39+
* name list live here; when the shared ones read more, this label follows
40+
* without an edit.
41+
*
42+
* Then the display shaping, unchanged: a value carrying `://` loses its
43+
* username and query string through the URL parser, or its userinfo segment
44+
* by hand when the parser rejects it. Values that aren't URLs — a sqlite path,
45+
* `:memory:`, the `(in-memory)` marker — pass through untouched unless the
46+
* shared grammar read a credential in them. Idempotent, so a call site that
47+
* can't tell whether its input was already redacted may apply it defensively.
3448
*/
3549
export function redactConnectionUrl(value: string): string {
36-
if (!value.includes('://')) return value;
50+
const withoutCredentials = redactUrlCredentials(value);
51+
if (!withoutCredentials.includes('://')) return withoutCredentials;
3752
try {
38-
const url = new URL(value);
53+
const url = new URL(withoutCredentials);
3954
url.username = '';
4055
url.password = '';
4156
// Query params are where tokens hide (`libsql://….turso.io?authToken=…`),
@@ -45,7 +60,7 @@ export function redactConnectionUrl(value: string): string {
4560
} catch {
4661
// Not parseable (a driver-specific dialect, a malformed URL). Drop the
4762
// userinfo segment by hand rather than printing the whole thing.
48-
return value.replace(/:\/\/[^@/]*@/, '://');
63+
return withoutCredentials.replace(/:\/\/[^@/]*@/, '://');
4964
}
5065
}
5166

‎packages/core/src/security/assemble-execution-context.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,41 @@ describe('ruling 6355206139 — the resolver’s audience stamp rides the envelo
591591
expect(Object.keys(assemble({ ...ANONYMOUS, audience: 'external' }))).not.toContain('audience');
592592
});
593593
});
594+
595+
// The guest envelope is the ONLY thing that tells a downstream create hook an
596+
// anonymous request is a caller at all. Create hooks such as `sys_attachment`'s
597+
// and `sys_comment`'s keep a bare-kernel carve-out — no hook session means an
598+
// internal, context-less engine call, skipped before any user check — and the
599+
// engine builds that session from the envelope's caller fields
600+
// (`buildSession`, objectql `engine-execution-plumbing.ts`), which does not
601+
// read `principalKind`. So the anonymous principal must stay identified by a
602+
// field that survives that hop, whatever else the face resolved or withheld.
603+
// objectql's own suite pins the hop itself; this pin holds the envelope end.
604+
describe('a guest request is a named caller, never an empty context', () => {
605+
const GUEST_SHAPES: Array<[string, ResolvedAuthzContext]> = [
606+
// The minimum: no session, no key, no guest anchor grants — nothing but
607+
// the fact that someone asked.
608+
['no tenant, no grants, no token', ANONYMOUS],
609+
// A face that serves the guest resolves the anchor's grants in the
610+
// organization ADR-0138 D4 derives; the identification must not depend on it.
611+
['guest anchor grants in an organization', baseAuthz({ tenantId: 'org1', permissions: ['task.read'] })],
612+
];
613+
614+
for (const [name, authz] of GUEST_SHAPES) {
615+
it(`an anonymous request keeps the guest position on its envelope (${name}), so create hooks see a caller`, () => {
616+
const ctx = assembleExecutionContextOrGuest({
617+
authz,
618+
oauth: undefined,
619+
// Everything a face could pass for an anonymous request, so a later
620+
// change that strips more of it cannot strip the identification too.
621+
localization: { timezone: 'Asia/Shanghai', locale: 'zh-CN', currency: 'CNY' },
622+
requestLocale: 'en-US',
623+
accessToken: undefined,
624+
authGate: undefined,
625+
});
626+
expect(ctx.userId).toBeUndefined();
627+
expect(ctx.isSystem).toBe(false);
628+
expect(ctx.positions).toEqual(['guest']);
629+
});
630+
}
631+
});

‎packages/objectql/src/engine-execution-plumbing.session-locale.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { describe, it, expect } from 'vitest';
11+
import { assembleExecutionContextOrGuest } from '@objectstack/core';
1112
import { buildSession } from './engine-execution-plumbing.js';
1213

1314
describe('[#26170] buildSession carries the caller\'s locale', () => {
@@ -25,3 +26,46 @@ describe('[#26170] buildSession carries the caller\'s locale', () => {
2526
}
2627
});
2728
});
29+
30+
// Create hooks with a bare-kernel carve-out (`sys_attachment`'s and
31+
// `sys_comment`'s) read "no hook session" as an internal, context-less engine
32+
// call and skip their user checks for it. That reading is sound only while
33+
// every request door hands the engine a context this function turns into a
34+
// session — the guest door included, whose envelope names no user. Built
35+
// through the REAL guest entry (`@objectstack/core`), not a literal, so a
36+
// change to what that entry emits is measured here rather than assumed.
37+
describe('a guest request reaches create hooks with a session, so an anonymous create is never treated as a bare-kernel call', () => {
38+
// The anonymous resolver's own answer for a request with no credential:
39+
// the initial context `resolveAuthzContext` returns before any principal
40+
// is found (`packages/core/src/security/resolve-authz-context.ts`).
41+
const anonymousAuthz = () => ({
42+
positions: [] as string[],
43+
permissions: [] as string[],
44+
directPermissions: [] as string[],
45+
systemPermissions: [] as string[],
46+
org_user_ids: [] as string[],
47+
accessible_org_ids: [] as string[],
48+
});
49+
50+
it('the guest envelope with no tenant, no grants and no token still yields a session that names no user', () => {
51+
const guest = assembleExecutionContextOrGuest({
52+
authz: anonymousAuthz(),
53+
oauth: undefined,
54+
localization: undefined,
55+
requestLocale: undefined,
56+
accessToken: undefined,
57+
authGate: undefined,
58+
});
59+
const session = buildSession(guest);
60+
expect(session).toBeDefined();
61+
expect(session?.userId).toBeUndefined();
62+
// Not the system arm either: the hooks test `isSystem` before the user.
63+
expect(session).not.toHaveProperty('isSystem');
64+
});
65+
66+
it('CONTROL: an envelope that names nothing the session copies yields no session — the bare-kernel reading', () => {
67+
// The carve-out's own premise, so the pin above cannot pass on a
68+
// `buildSession` that answers a session for every input.
69+
expect(buildSession({ principalKind: 'guest' } as any)).toBeUndefined();
70+
});
71+
});

0 commit comments

Comments
 (0)