@undefineds.co/xpod 0.4.31 → 0.4.33

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.
@@ -616,7 +616,10 @@ class AiGatewayService {
616
616
  && !explicitCredentialIdFor(request);
617
617
  }
618
618
  builtinRoute(model) {
619
- const requested = model?.trim() || DeploymentBuiltinConnection_1.DEPLOYMENT_BUILTIN_CONNECTION_ID;
619
+ // Route evidence carries the BARE canonical model: a client that followed
620
+ // the advertised `xpod-builtin` provider namespace must not leak that
621
+ // qualified form into the route or the upstream request.
622
+ const requested = this.builtin.canonicalModel(model) ?? model?.trim() ?? DeploymentBuiltinConnection_1.DEPLOYMENT_BUILTIN_CONNECTION_ID;
620
623
  const provider = {
621
624
  id: this.builtin.id,
622
625
  label: this.builtin.label,
@@ -32,6 +32,17 @@ export declare class DeploymentBuiltinConnection {
32
32
  fetch?: typeof fetch;
33
33
  });
34
34
  get modelIds(): readonly string[];
35
+ /**
36
+ * Bare canonical id for a model this connection owns, else undefined.
37
+ *
38
+ * The provider pool advertises this built-in as `xpod-builtin`, so a client
39
+ * following that provider/model reference sends `xpod-builtin/linx`. Its OWN
40
+ * prefix is stripped once; a bare declared id is returned as-is. Anything
41
+ * else (another provider's prefix, `custom/linx`, an undeclared id, empty)
42
+ * yields undefined so callers leave the reference untouched.
43
+ */
44
+ canonicalModel(model: string | undefined): string | undefined;
45
+ /** True only for this connection's bare ids or its own qualified namespace. */
35
46
  owns(model: string | undefined): boolean;
36
47
  /** Static projection: listing never depends on upstream reachability or the caller's Pod. */
37
48
  listModels(): GatewayModelProjection[];
@@ -67,9 +67,29 @@ class DeploymentBuiltinConnection {
67
67
  get modelIds() {
68
68
  return exports.DEPLOYMENT_BUILTIN_MODEL_IDS;
69
69
  }
70
+ /**
71
+ * Bare canonical id for a model this connection owns, else undefined.
72
+ *
73
+ * The provider pool advertises this built-in as `xpod-builtin`, so a client
74
+ * following that provider/model reference sends `xpod-builtin/linx`. Its OWN
75
+ * prefix is stripped once; a bare declared id is returned as-is. Anything
76
+ * else (another provider's prefix, `custom/linx`, an undeclared id, empty)
77
+ * yields undefined so callers leave the reference untouched.
78
+ */
79
+ canonicalModel(model) {
80
+ if (typeof model !== 'string')
81
+ return undefined;
82
+ const trimmed = model.trim();
83
+ if (!trimmed)
84
+ return undefined;
85
+ const prefix = `${this.id}/`;
86
+ // Only declared ids qualify; `xpod-builtin/other` must not become `other`.
87
+ const bare = trimmed.startsWith(prefix) ? trimmed.slice(prefix.length) : trimmed;
88
+ return exports.DEPLOYMENT_BUILTIN_MODEL_IDS.includes(bare) ? bare : undefined;
89
+ }
90
+ /** True only for this connection's bare ids or its own qualified namespace. */
70
91
  owns(model) {
71
- return typeof model === 'string'
72
- && exports.DEPLOYMENT_BUILTIN_MODEL_IDS.includes(model.trim());
92
+ return this.canonicalModel(model) !== undefined;
73
93
  }
74
94
  /** Static projection: listing never depends on upstream reachability or the caller's Pod. */
75
95
  listModels() {
@@ -91,7 +111,11 @@ class DeploymentBuiltinConnection {
91
111
  if (!body || typeof body !== 'object' || Array.isArray(body))
92
112
  return body;
93
113
  const record = { ...body };
94
- const model = typeof record.model === 'string' ? record.model.trim() : '';
114
+ // Normalize the caller's own-qualified reference to the bare canonical id
115
+ // BEFORE the deployment model map, so the upstream receives the configured
116
+ // physical model and never `xpod-builtin/linx`.
117
+ const model = this.canonicalModel(typeof record.model === 'string' ? record.model : undefined)
118
+ ?? (typeof record.model === 'string' ? record.model.trim() : '');
95
119
  record.model = this.modelMap[model] ?? model;
96
120
  // Attribution for the ai-gateway (LiteLLM treats `user` as the end user): the verified WebID.
97
121
  const webId = (0, AuthContext_1.getWebId)(auth);
@@ -6,6 +6,8 @@ export interface SolidTokenAuthenticatorOptions {
6
6
  */
7
7
  resolveAccountId?: (webId: string) => Promise<string | undefined>;
8
8
  publicBaseUrl?: string;
9
+ /** Published API endpoint for this Cloud deployment, independent of its identity origin. */
10
+ apiBaseUrl?: string;
9
11
  internalBaseUrl?: string;
10
12
  }
11
13
  /**
@@ -16,13 +18,14 @@ export declare class SolidTokenAuthenticator implements Authenticator {
16
18
  private readonly verify;
17
19
  private readonly resolveAccountId?;
18
20
  private readonly publicOrigin?;
21
+ private readonly canonicalOrigins;
19
22
  constructor(options?: SolidTokenAuthenticatorOptions);
20
23
  canAuthenticate(request: IncomingMessage): boolean;
21
24
  authenticate(request: IncomingMessage): Promise<AuthResult>;
22
25
  private buildRequestUrl;
23
26
  private verifyRequest;
24
27
  private trustedCanonicalRouteUrl;
25
- private configuredCanonicalRequestUrl;
28
+ private configuredCanonicalRequestUrls;
26
29
  private hasLocalRouteHeader;
27
30
  private firstHeaderValue;
28
31
  private pathAndSearch;
@@ -7,6 +7,20 @@ const SolidTokenCaches_1 = require("../../authentication/SolidTokenCaches");
7
7
  const ConfiguredLoopbackSolidTokenVerifier_1 = require("../../authentication/ConfiguredLoopbackSolidTokenVerifier");
8
8
  const SOLID_LOCAL_ROUTE_CANONICAL_URL_HEADER = 'x-xpod-canonical-url';
9
9
  const SOLID_LOCAL_ROUTE_LOCAL_URL_HEADER = 'x-xpod-local-route-url';
10
+ function configuredApiOrigin(value) {
11
+ if (!value?.trim())
12
+ return undefined;
13
+ try {
14
+ const url = new URL(value);
15
+ if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash) {
16
+ return undefined;
17
+ }
18
+ return url.origin;
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ }
10
24
  /**
11
25
  * Parse one Solid Authorization header value into its canonical scheme and token.
12
26
  *
@@ -40,6 +54,12 @@ class SolidTokenAuthenticator {
40
54
  this.resolveAccountId = options.resolveAccountId;
41
55
  const { issuerKeySetCache, webIdIssuersCache, publicOrigin } = (0, SolidTokenCaches_1.createRoutedSolidTokenCaches)(options);
42
56
  this.publicOrigin = publicOrigin;
57
+ // Discovery and trusted local-route hints still use the identity authority.
58
+ // Only the no-hint retry also accepts this deployment's configured API origin.
59
+ this.canonicalOrigins = [...new Set([
60
+ publicOrigin,
61
+ configuredApiOrigin(options.apiBaseUrl),
62
+ ].filter((origin) => origin !== undefined))];
43
63
  const loopbackOrigin = (0, ConfiguredLoopbackSolidTokenVerifier_1.configuredHttpLoopbackOrigin)(publicOrigin);
44
64
  this.verify = loopbackOrigin
45
65
  ? (0, ConfiguredLoopbackSolidTokenVerifier_1.createConfiguredLoopbackSolidTokenVerifier)({
@@ -143,22 +163,20 @@ class SolidTokenAuthenticator {
143
163
  if (!dpopHeader) {
144
164
  throw error;
145
165
  }
146
- const configuredCanonicalUrl = this.configuredCanonicalRequestUrl(request, url);
147
- if (!configuredCanonicalUrl) {
148
- throw error;
149
- }
150
- try {
151
- return await this.verify(authorization, {
152
- header: dpopHeader,
153
- method,
154
- url: configuredCanonicalUrl,
155
- });
156
- }
157
- catch {
158
- // Retain the primary diagnostic when both attempts fail: reporting the
159
- // retry's htu mismatch would hide the reason the caller actually failed.
160
- throw error;
166
+ for (const configuredCanonicalUrl of this.configuredCanonicalRequestUrls(request, url)) {
167
+ try {
168
+ return await this.verify(authorization, {
169
+ header: dpopHeader,
170
+ method,
171
+ url: configuredCanonicalUrl,
172
+ });
173
+ }
174
+ catch {
175
+ // Every retry performs full verification. Preserve the primary error
176
+ // if none of the deployment's configured authorities verifies it.
177
+ }
161
178
  }
179
+ throw error;
162
180
  }
163
181
  }
164
182
  trustedCanonicalRouteUrl(request) {
@@ -194,20 +212,20 @@ class SolidTokenAuthenticator {
194
212
  }
195
213
  return canonicalUrl.href;
196
214
  }
197
- configuredCanonicalRequestUrl(request, primaryUrl) {
198
- if (!this.publicOrigin || this.hasLocalRouteHeader(request)) {
199
- return undefined;
200
- }
201
- const publicUrl = new URL(this.publicOrigin);
202
- if (publicUrl.protocol !== 'https:') {
203
- return undefined;
215
+ configuredCanonicalRequestUrls(request, primaryUrl) {
216
+ if (this.hasLocalRouteHeader(request)) {
217
+ return [];
204
218
  }
205
219
  const requestPath = this.pathAndSearch(request.url ?? '/');
206
220
  if (!requestPath) {
207
- return undefined;
221
+ return [];
208
222
  }
209
- const configuredUrl = new URL(requestPath, this.publicOrigin).href;
210
- return configuredUrl === primaryUrl ? undefined : configuredUrl;
223
+ return this.canonicalOrigins.flatMap((origin) => {
224
+ if (new URL(origin).protocol !== 'https:')
225
+ return [];
226
+ const configuredUrl = new URL(requestPath, origin).href;
227
+ return configuredUrl === primaryUrl ? [] : [configuredUrl];
228
+ });
211
229
  }
212
230
  hasLocalRouteHeader(request) {
213
231
  return this.firstHeaderValue(request.headers[SOLID_LOCAL_ROUTE_CANONICAL_URL_HEADER]) !== undefined ||
@@ -574,6 +574,7 @@ function registerCommonServices(container) {
574
574
  publicBaseUrl: config.edition === 'local' && config.publicUrl
575
575
  ? (0, storage_base_url_1.resolveLocalStorageProviderBaseUrl)(config)
576
576
  : config.solidBaseUrl,
577
+ apiBaseUrl: config.edition === 'cloud' ? config.apiBaseUrl : undefined,
577
578
  // Token discovery is a public OIDC concern. WebID/JWKS verification is
578
579
  // an internal service call and must not hairpin through public ingress.
579
580
  internalBaseUrl: resolveHostedPodCssBaseUrl(config),
@@ -179,6 +179,7 @@ function loadConfigFromEnv() {
179
179
  corsOrigins: process.env.CORS_ORIGINS?.split(',').map(s => s.trim()) ?? ['*'],
180
180
  cssTokenEndpoint: resolveCssTokenEndpoint(),
181
181
  solidBaseUrl,
182
+ apiBaseUrl: normalizeOptionalUrl(process.env.XPOD_API_BASE_URL),
182
183
  solidRootFilePath: path.resolve(rootDir),
183
184
  aiConnectionInvocationSecret: process.env.XPOD_AI_CONNECTION_INVOCATION_SECRET,
184
185
  aiConnectionInvocationKeyId: process.env.XPOD_AI_CONNECTION_INVOCATION_KEY_ID,
@@ -117,6 +117,8 @@ export interface ApiContainerConfig {
117
117
  /** CSS Token 端点 */
118
118
  cssTokenEndpoint: string;
119
119
  solidBaseUrl?: string;
120
+ /** Published API endpoint from XPOD_API_BASE_URL; distinct from the Solid identity origin. */
121
+ apiBaseUrl?: string;
120
122
  /** Captured CSS filesystem root for this runtime, independent of later process.env changes. */
121
123
  solidRootFilePath?: string;
122
124
  /** Stateless AI Connections invocation token signing config. */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "sourceAuthority": {
4
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
4
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
5
5
  "tracked": true,
6
6
  "dirty": false,
7
7
  "snapshotSHA256": "85f739d81735baf4e1263e55c2542335233393872ee761179ff0b9fa4411879e",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "sourceAuthority": {
4
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
4
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
5
5
  "tracked": true,
6
6
  "dirty": false,
7
7
  "snapshotSHA256": "85f739d81735baf4e1263e55c2542335233393872ee761179ff0b9fa4411879e",
@@ -12,7 +12,7 @@
12
12
  {
13
13
  "path": "build-provenance.json",
14
14
  "bytes": 1727,
15
- "sha256": "988246ea946941ec55c1bd1ab46ce4c518dad9634adc3803e8183ffec8d3e5af"
15
+ "sha256": "707d41090d3b44c9b3c23e94e9fc1e4f23ad8248ccc4da37d938e6af4fdcceb3"
16
16
  },
17
17
  {
18
18
  "path": "generated/provider-catalog/index.json",
@@ -322,7 +322,7 @@
322
322
  {
323
323
  "path": "source-inventory.json",
324
324
  "bytes": 4713,
325
- "sha256": "866f7c5086422a4542e4d0c5ad4b366720e3f0758dfe5f1adb3288b18ffd9684"
325
+ "sha256": "cf0f1bbcfd5b20c36039a4296ea3dc48c1a5bac63b2aaa13d94ec3826b8716c0"
326
326
  }
327
327
  ]
328
328
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "sourceAuthority": {
4
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
4
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
5
5
  "tracked": true,
6
6
  "dirty": false,
7
7
  "snapshotSHA256": "85f739d81735baf4e1263e55c2542335233393872ee761179ff0b9fa4411879e",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "sourceAuthority": {
4
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
4
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
5
5
  "tracked": true,
6
6
  "dirty": false,
7
7
  "snapshotSHA256": "c3b65827fdfc0e13c743cd5129b9db7626ec2419e12b06d8478d97fc859e851a",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "sourceAuthority": {
4
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
4
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
5
5
  "tracked": true,
6
6
  "dirty": false,
7
7
  "snapshotSHA256": "c3b65827fdfc0e13c743cd5129b9db7626ec2419e12b06d8478d97fc859e851a",
@@ -12,7 +12,7 @@
12
12
  {
13
13
  "path": "build-provenance.json",
14
14
  "bytes": 398,
15
- "sha256": "f2844f6367e35d1e9657767a86fe7a63965765235a95ad971dea9997ae9de081"
15
+ "sha256": "eb2c33afee31058e69d3670b7e6a7f673cb21c33bdb942aaa23a876ef2848d39"
16
16
  },
17
17
  {
18
18
  "path": "source/LICENSE",
@@ -52,7 +52,7 @@
52
52
  {
53
53
  "path": "source-inventory.json",
54
54
  "bytes": 1585,
55
- "sha256": "8ed9730d08da1e0665c0b9faadc6db66cc376a2fd6576e236e4fbef5a26d55cf"
55
+ "sha256": "9dd493e84ece7bcf1e5089d8273ec42e4bc2d202beb83f89284952b601c71d9b"
56
56
  }
57
57
  ]
58
58
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "sourceAuthority": {
4
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
4
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
5
5
  "tracked": true,
6
6
  "dirty": false,
7
7
  "snapshotSHA256": "c3b65827fdfc0e13c743cd5129b9db7626ec2419e12b06d8478d97fc859e851a",
@@ -5,7 +5,7 @@
5
5
  "version": "0.1.0-preview.2",
6
6
  "bunVersion": "1.4.2"
7
7
  },
8
- "indexSHA256": "bc49acbcdc248ed2116be614447d7ebfb40f6445b90b681b3448b6c437df6eca",
8
+ "indexSHA256": "c65e62014a116bb2196474cd542e477d4b33c6372bd751a841a4a793c7f02363",
9
9
  "outputPayloads": {
10
10
  "esmSHA256": "7f610395a47a79acd1bb2181a71a16e887272fa4e5522fa095db78625f3c8eb0"
11
11
  }
@@ -159,7 +159,7 @@
159
159
  }
160
160
  ],
161
161
  "sourceAuthority": {
162
- "sourceCommit": "4194795915ac5f956cd593131647ece7049be24d",
162
+ "sourceCommit": "db6c51aa1a0a9551f8b7b6149767f188b101c9a4",
163
163
  "dirty": false,
164
164
  "snapshotSHA256": "a198c5f28999d0c763c3bb5d166823a5a5eb0eff8e7e4557b7b8d299200198a9",
165
165
  "scope": "CLI source plus explicitly mapped canonical host and runtime-client source; no claim of release acceptance or external dependency closure."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@undefineds.co/xpod",
3
- "version": "0.4.31",
3
+ "version": "0.4.33",
4
4
  "description": "Xpod is an extended Community Solid Server, offering rich-feature, production-level Solid Pod and identity management.",
5
5
  "repository": "https://github.com/undefinedsco/xpod",
6
6
  "author": "developer@undefineds.co",
@@ -388,7 +388,7 @@
388
388
  }
389
389
  },
390
390
  "optionalDependencies": {
391
- "@undefineds.co/xpod-darwin-arm64": "0.4.31",
391
+ "@undefineds.co/xpod-darwin-arm64": "0.4.33",
392
392
  "@undefineds.co/drizzle-solid": "0.3.26",
393
393
  "@undefineds.co/extensions": "0.1.0",
394
394
  "@undefineds.co/ai-connections": "0.1.6",