Skip to content

Commit 268167f

Browse files
committed
Merge origin/main into claude/project-thread-hzucdt
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jU8C3iu8fsXdU4Rm8o
2 parents 3c4fff9 + 133f75a commit 268167f

40 files changed

Lines changed: 2277 additions & 74 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/cli': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
fix(cli,runtime): the organization-ownership refusal names the database for `os dev -d`, and the driver and token `os start` / `os dev` were given by flag
7+
8+
Clause-②: yes (widening) — `@objectstack/runtime`'s published `OrganizationOwnershipBootGuardOptions` gains two optional members, `databaseDriver` and `databaseAuthTokenFromFlag`, and the refusal's two ceremony commands set `OS_DATABASE_DRIVER` and `OS_DATABASE_AUTH_TOKEN` in front when `--database-driver` / `--database-auth-token` chose them; `os dev`'s `--dev` commands carry `--database-url` when `-d` chose the database. What `os dev`, `os start`, `os serve` and `os migrate organization-ownership` accept or refuse is unchanged.
9+
Metadata-protocol: none
10+
11+
`os dev -d URL` served the database `-d` chose, but when the organization-ownership boot guard refused it, the refusal printed `os migrate organization-ownership --dev --out PLAN` (and the `--apply` command) with no database, and `os dev`'s own line for a database it does not upgrade in place (anything that is not a local SQLite file) repeated that bare spelling. Run as printed, the ceremony planned the project's default database instead. `os dev` now hands its `serve` child the database it resolved through the same internal channel `os start` uses (#31488), so both commands read `os migrate organization-ownership --dev --database-url URL …`, a URL with a credential read from `"${OS_DATABASE_URL:?…}"` as before. `os dev`'s own line now points at the two commands the refusal names instead of spelling a bare one.
12+
13+
`os start` and `os dev` put `--database-driver` and `--database-auth-token` in the child's environment only (`OS_DATABASE_DRIVER`, `OS_DATABASE_AUTH_TOKEN`), and the ceremony reads those two variables (it has no flag for either), so the printed commands opened the database with another driver or without its token. They now set both in front of the command: `OS_DATABASE_DRIVER=turso OS_DATABASE_AUTH_TOKEN="${OS_DATABASE_AUTH_TOKEN:?…}" os migrate organization-ownership …`. The token is never printed and never reaches the guard: the command re-exports the shell's own `OS_DATABASE_AUTH_TOKEN`, the refusal says to export it, and the shell stops with that message when it is unset. A driver or token the operator exported themselves is in their shell already and is not repeated.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/service-settings': patch
3+
---
4+
5+
fix(service-settings): a select, radio or multiselect setting refuses every value when its option source answers an empty list
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) no key of any schema is added, removed or re-shaped and no stored row is read differently: the narrowing is one runtime refusal at the settings save door and the OS_* env door, for a select-family key whose registered option source answers an empty list, and its remedy is a value the source offers once it offers one, so there is nothing for `objectstack migrate meta` to rewrite. A value already stored is not re-judged. -->
11+
12+
A select, radio or multiselect key whose options come from a registered option source (`registerOptionSource`) was judged against that list only when the list had entries. When the source answered an empty list, any value was saved and any `OS_*` override was put in force. Now no value is admitted then: the save door refuses it with `invalid_option` ("… offers no value to choose from right now."), and the env door logs the override as not in force, as #31422 made the `map` family judge its keys. This narrows what is accepted. During the boot, while the option verdicts are held (`holdOptionSourceVerdicts`, sealed at `kernel:bootstrapped`), an override is still taken in force and judged at the seal, so a list the boot is still filling refuses nothing early. A key with no source, or whose source cannot answer, is judged against its declared options as before. Also, the env door's "said once" record now keys a structured value by a stable serialisation, so a second, different bad map under one `OS_*` variable is reported too (before, every map counted as the same value).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): a declared app endpoint runs the environment-membership check
6+
7+
Clause-②: yes (widening) — `@objectstack/runtime`'s published `HttpDispatcher` gains one public method, `environmentMembershipRefusal(context)`.
8+
Metadata-protocol: none
9+
10+
On a multi-environment host that enforces environment membership, a declared app endpoint (`/api/v1/apps/…`) now answers a signed-in caller who is not a member of the environment the request resolves to with `403 PROJECT_MEMBERSHIP_REQUIRED`, as the built-in routes do, whether or not the endpoint sets `authRequired`. The check runs after the endpoint is matched and its policies admitted the caller, so a path no declaration owns keeps its `404` and an anonymous caller of an `authRequired` endpoint its `401`. Members, anonymous callers, and hosts without environment scoping or with the check turned off (`api.enforceProjectMembership: false`) are unchanged. `HttpDispatcher` gains `environmentMembershipRefusal(context)`, and `runAppEndpointStep` an optional `membership` input.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
'@objectstack/spec': patch
4+
---
5+
6+
fix(plugin-auth): an auth request is judged and executed as one account
7+
8+
Clause-②: yes
9+
Metadata-protocol: none
10+
11+
A request whose session cookie and bearer token name two different signed-in accounts is refused before anything runs, with `401 CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`, and nothing is read or written for either account. It applies to every better-auth endpoint (over HTTP and to the in-process session read every data door makes) and to the raw ObjectStack routes on the identity mount. One credential alone, two credentials that name the same account (two sessions of one user included), and a credential that names no signed-in account are unaffected. An API key is not a session credential for this rule; each door keeps its existing one-principal rule for keys. A session read that cannot answer refuses too, as an outage (`503 SERVICE_UNAVAILABLE`), and so does the identity mount when the judgment cannot be reached at all.
12+
13+
`CREDENTIALS_NAME_DIFFERENT_ACCOUNTS` is registered in the `@objectstack/spec` error-code ledger under `@objectstack/plugin-auth`.
14+
15+
A successful `/change-password` stamps `password_changed_at`, clears an administrator's forced change and appends the history entry on the account the change acted on, and only when the password checks before it ran for that account; otherwise none of them lands, and the operator is told.
16+
17+
`/admin/revoke-user-session` refuses a token that identifies no session (`404 RESOURCE_NOT_FOUND`) for a caller signed in by bearer alone, as it already did on the cookie lane.
18+
19+
The Console needs no change: its session read already treats any refused read as a stale token, retrying with the cookie alone and dropping the token.

‎content/docs/references/api/automation-api.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ const result = AutomationApiErrorCode.parse(data);
417417

418418
| Property | Type | Required | Description |
419419
| :--- | :--- | :--- | :--- |
420-
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +363 more>` | ✅ | The inner refusal's code in its WIRE spelling - the ADR-0112 member a record save of the same write answers in `error.code` (e.g. `UNIQUE_VIOLATION`); the closed set `ApiErrorSchema.code` parses against |
420+
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +364 more>` | ✅ | The inner refusal's code in its WIRE spelling - the ADR-0112 member a record save of the same write answers in `error.code` (e.g. `UNIQUE_VIOLATION`); the closed set `ApiErrorSchema.code` parses against |
421421
| **message** | `string` | ✅ | The inner refusal's own diagnostic text, verbatim, without the node and operation prefixes the run's failure text adds |
422422

423423
### Allowed Values: `FlowInnerRefusal.code`
@@ -520,6 +520,7 @@ const result = AutomationApiErrorCode.parse(data);
520520
* `CONNECTOR_UPSTREAM_CHANGED`
521521
* `CONNECTOR_UPSTREAM_UNAVAILABLE`
522522
* `CREATE_FAILED`
523+
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
523524
* `CUBE_NOT_FOUND`
524525
* `DATASET_INVALID`
525526
* `DATASOURCE_ADMIN_ERROR`

‎content/docs/references/api/contract.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const result = ApiErrorSchema.parse(data);
2828

2929
| Property | Type | Required | Description |
3030
| :--- | :--- | :--- | :--- |
31-
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +363 more>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
31+
| **code** | `Enum<'VALIDATION_ERROR' \| 'INVALID_FIELD' \| 'MISSING_REQUIRED_FIELD' \| 'INVALID_FORMAT' \| 'VALUE_TOO_LONG' \| 'VALUE_TOO_SHORT' \| 'VALUE_OUT_OF_RANGE' \| … +364 more>` | ✅ | Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages) |
3232
| **declaredCode** | `string` | optional | The producer-declared code, verbatim, when it is not a member of the closed `code` vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112) |
3333
| **message** | `string` | ✅ | Readable error message |
3434
| **userMessage** | `string` | optional | Producer-marked user-facing refusal text, verbatim. Present exactly when the producer opted in at throw time; consumers render it to end users and keep their generic substitution for anything unmarked. Status-agnostic; never replaces `message`. |
@@ -138,6 +138,7 @@ const result = ApiErrorSchema.parse(data);
138138
* `CONNECTOR_UPSTREAM_CHANGED`
139139
* `CONNECTOR_UPSTREAM_UNAVAILABLE`
140140
* `CREATE_FAILED`
141+
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
141142
* `CUBE_NOT_FOUND`
142143
* `DATASET_INVALID`
143144
* `DATASOURCE_ADMIN_ERROR`

‎content/docs/references/api/error-code-ledger.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ const result = ErrorCode.parse(data);
305305
* `CONNECTOR_UPSTREAM_CHANGED`
306306
* `CONNECTOR_UPSTREAM_UNAVAILABLE`
307307
* `CREATE_FAILED`
308+
* `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`
308309
* `CUBE_NOT_FOUND`
309310
* `DATASET_INVALID`
310311
* `DATASOURCE_ADMIN_ERROR`

‎packages/cli/src/commands/dev.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ import { claudeMcpAddLine, MCP_ENDPOINT_PATH } from './mcp/connect.js';
4242
// #12620 and #12662 protected against.
4343
import { describePortSource, parseRequestedPort, formatInvalidPortNotice, portFlagEnv } from '../utils/port-contract.js';
4444
import { applyCryptoKeyFileChannel } from '../utils/internal-crypto-key-file-channel.js';
45+
import {
46+
ceremonyDatabaseUrl,
47+
writeCeremonyConnectionChannel,
48+
writeCeremonyDatabaseChannel,
49+
} from '../utils/internal-ceremony-database-channel.js';
4550
import { startDevDeployKey, type DeployKeyHandle } from '../utils/dev-deploy-key.js';
4651
// The ONE dev-TLS contract, shared with the `serve` child this command spawns
4752
// (#16804). ⛔ Nothing about certificates is declared in this file, and ⛔ no
@@ -841,6 +846,17 @@ export default class Dev extends Command {
841846
...(flags['auth-secret'] ? { OS_AUTH_SECRET: flags['auth-secret'] } : {}),
842847
};
843848
applyFreshHomeChannel(localEnv, freshHome);
849+
// [#31547] The database `-d` (or `--fresh`) chose is one the ceremony the
850+
// ownership refusal names does not find on its own, and the driver and
851+
// token the two flags above put here are not in the developer's shell:
852+
// the child names them in both `--dev` commands, read from the
853+
// resolution above (the one this boot serves), never re-resolved. Same
854+
// channel as `os start` (#31488). `os dev` has no `--home`.
855+
writeCeremonyDatabaseChannel(localEnv, ceremonyDatabaseUrl(resolvedDb, { homeFlag: undefined }));
856+
writeCeremonyConnectionChannel(localEnv, {
857+
databaseDriver: flags['database-driver'],
858+
databaseAuthToken: flags['database-auth-token'],
859+
});
844860
// The data key's file: the ONE answer `os start` takes too (#29934), so a
845861
// secret saved here reads back under `os start` over the same project —
846862
// and the file an earlier `os start` kept in the project is still read.

‎packages/cli/src/commands/serve.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { mountsAiServicePlugin, resolveAiServiceLoad, resolveOptionalPluginLoad
1414
import { registerInstalledPlugins } from '../utils/installed-plugins-boot.js';
1515
import { readInternalArtifactPath, readInternalConfigOutputPath } from '../utils/internal-artifact-channel.js';
1616
import { readAuthSecretFileChannel } from '../utils/internal-auth-secret-channel.js';
17-
import { readCeremonyDatabaseChannel } from '../utils/internal-ceremony-database-channel.js';
17+
import { readCeremonyConnectionChannel, readCeremonyDatabaseChannel } from '../utils/internal-ceremony-database-channel.js';
1818
import { compileForDevBoot, devCompilesAtBoot } from '../utils/dev-compile-at-boot.js';
1919
import { makeDirectorySync } from '../utils/make-directory.js';
2020
// The precedence's last rung — whether the cwd config takes part — decided by
@@ -4218,12 +4218,14 @@ export default class Serve extends Command {
42184218
// persisted in its home names that file, so the ceremony runs with the
42194219
// secret this server composes its security plugin with. A boot on a
42204220
// database the ceremony would not find by default (`os start -d` or
4221-
// `--home`, #31488) names it, so the commands plan this database.
4221+
// `--home`, #31488; `os dev -d`, #31547) names it, so the commands plan
4222+
// this database, with the driver and token its parent's flags chose.
42224223
const ceremonyDatabase = readCeremonyDatabaseChannel(process.env);
42234224
await kernel.use(new OrganizationOwnershipBootGuardPlugin({
42244225
dev: isDev,
42254226
authSecretFile: readAuthSecretFileChannel(process.env),
42264227
...(ceremonyDatabase ? { databaseUrl: ceremonyDatabase } : {}),
4228+
...readCeremonyConnectionChannel(process.env),
42274229
}));
42284230
trackPlugin('OrganizationOwnershipBootGuard');
42294231
}

‎packages/cli/src/commands/start.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import {
2323
import { ServeRestartCoordinator } from '../utils/dev-restart.js';
2424
import { readEnvWithDeprecation } from '@objectstack/types';
2525
import { writeAuthSecretFileChannel } from '../utils/internal-auth-secret-channel.js';
26-
import { ceremonyDatabaseUrl, writeCeremonyDatabaseChannel } from '../utils/internal-ceremony-database-channel.js';
26+
import {
27+
ceremonyDatabaseUrl,
28+
writeCeremonyConnectionChannel,
29+
writeCeremonyDatabaseChannel,
30+
} from '../utils/internal-ceremony-database-channel.js';
2731
import { applyCryptoKeyFileChannel } from '../utils/internal-crypto-key-file-channel.js';
2832
import { resolveStartHome } from '../utils/start-home.js';
2933
// The ONE port contract, shared with `dev` and with the `serve` child this
@@ -507,6 +511,12 @@ export default class Start extends Command {
507511
// child names it in both commands, read from the resolution above — the
508512
// one this boot serves — never re-resolved.
509513
writeCeremonyDatabaseChannel(localEnv, ceremonyDatabaseUrl(resolvedDb, { homeFlag: flags.home }));
514+
// [#31547] The driver and the token the two flags above put in the child's
515+
// environment only: the commands set them in front, the token by reference.
516+
writeCeremonyConnectionChannel(localEnv, {
517+
databaseDriver: flags['database-driver'],
518+
databaseAuthToken: flags['database-auth-token'],
519+
});
510520
// NODE_ENV is only forced to production when the user has not set it.
511521
// Allows `NODE_ENV=development objectstack start` to work for debugging.
512522
//

0 commit comments

Comments
 (0)