Skip to content

Commit 4824fe2

Browse files
Merge la3d/lws-drain: representation preservation + 304/406 + --lws-config + MCP affordances + federation hardening (spec 2026-07-11)
2 parents be2ddba + 0e979ad commit 4824fe2

40 files changed

Lines changed: 1638 additions & 178 deletions

‎bin/jss.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ program
9595
.option('--lws', 'Enable the W3C Linked Web Storage surface (application/lws+json containers)')
9696
.option('--lws-type-index', 'Enable the LWS Type Index/Search services (default on when --lws)')
9797
.option('--no-lws-type-index', 'Disable the LWS Type Index/Search services')
98-
.option('--lws-profile-index <path>', 'Advertise a ProfileIndexService at this pod path in the storage description (requires --lws)')
9998
.option('--lws-profile-conneg', 'Enable content negotiation by profile (default on when --lws)')
10099
.option('--no-lws-profile-conneg', 'Disable content negotiation by profile')
101-
.option('--lws-void <path>', 'Serve /.well-known/void as a 303 to this pod path and advertise a VoidService in the storage description (requires --lws)')
100+
.option('--lws-config <path>', 'Pod resource declaring LWS service endpoints as data ({ profileIndex, void }, requires --lws)')
102101
.option('--notifications', 'Enable WebSocket notifications')
103102
.option('--no-notifications', 'Disable WebSocket notifications')
104103
.option('--idp', 'Enable built-in Identity Provider')
@@ -165,6 +164,7 @@ program
165164
.option('--mcp', 'Enable MCP (Model Context Protocol) server at /mcp — pod as a tool surface for agents (#490)')
166165
.option('--no-mcp', 'Disable MCP server')
167166
.option('--mcp-credential-policy <policy>', "Credential tier required on /mcp: 'trusted-local' (default) or 'audience-bound' (refuses the replayable bearer, requires LWS-CID/Solid-OIDC DPoP)")
167+
.option('--lws-federation-private', 'Allow the MCP federation arm (read_resource remote reads) to reach loopback/RFC-1918/link-local/cloud-metadata hosts (default: blocked)')
168168
.option('-q, --quiet', 'Suppress log output')
169169
.option('--log-level <level>', 'Log level: error, warn, info, debug (default: info)')
170170
.option('--print-config', 'Print configuration and exit')
@@ -231,9 +231,8 @@ program
231231
conneg: config.conneg,
232232
lws: config.lws,
233233
lwsTypeIndex: config.lwsTypeIndex,
234-
lwsProfileIndex: config.lwsProfileIndex,
235234
lwsProfileConneg: config.lwsProfileConneg,
236-
lwsVoid: config.lwsVoid,
235+
lwsConfig: config.lwsConfig,
237236
notifications: config.notifications,
238237
idp: config.idp,
239238
idpIssuer: idpIssuer,
@@ -287,6 +286,7 @@ program
287286
mongoDatabase: config.mongoDatabase,
288287
mcp: config.mcp,
289288
mcpCredentialPolicy: config.mcpCredentialPolicy,
289+
lwsFederationPrivate: config.lwsFederationPrivate,
290290
});
291291

292292
await server.listen({ port: config.port, host: config.host });

‎docs/mcp.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Ten tools: eight core + two convenience.
104104
| `write_acl` | persist a structured ACL to the resource's `.acl` | Control + anti-lockout |
105105
| `lws_type_search` | CNF `type` (+ `describedby`) query, WAC-filtered, no-oracle | reuses the authorized-resources walk |
106106
| `subscribe` | SSE stream of `resource_changed` events, WAC-filtered per event | Read per event |
107-
| `read_resource` | Read any resource by its real `https://` URL — one-Web: this pod's own uri dispatches as a local read (same resolver as `resources/read`), any other origin is a federation-gated remote GET (incl. that pod's storage description). Returns two content blocks: body, then metadata `{ uri, mimeType, links }`. Local `links`: `up` (parent container, omitted for `/.well-known/*` — those have no parent to walk to), `storageDescription`, `describedby` (optional, from `.meta`). Remote `links`: `context`, `alternate`, `linkset` (from Link headers, passed through verbatim). | local: Read; remote: caller needs `acl:Write` on `<pod>/private/federation/`, depth-capped at 3 |
107+
| `read_resource` | Read any resource by its real `https://` URL — one-Web: this pod's own uri dispatches as a local read (same resolver as `resources/read`), any other origin is a federation-gated remote GET (incl. that pod's storage description). Returns two content blocks: body, then metadata `{ uri, mimeType, links }` (`mimeType` is the resource's real stored content type, e.g. `text/markdown` — independent of the body being fenced as untrusted). Local `links`: `up` (parent container, omitted for `/.well-known/*` — those have no parent to walk to), `storageDescription`, `describedby` (optional, from `.meta`), `canonical`/`alternates` (optional, authz-filtered `altr:` representations declared on `.meta` — an alternate the caller can't Read is simply absent, no-oracle). Remote `links`: `context`, `alternate`, `linkset` (from Link headers, passed through verbatim). | local: Read; remote: caller needs `acl:Write` on `<pod>/private/federation/`, depth-capped at 3 |
108108
| `list_resources` | The model-callable twin of `resources/list` — this pod's fixed entry resources + the real-URI template. Returns metadata object with `resources` array (fixed entries like `storage-description`, `pod-info`, `skills`) and `templates` array (the real-URI template). | none (fixed, public shape) |
109109

110110
Writes (`write_resource`/`create_resource`, and `put_typed_resource` below) route through the shared LWS admission core (SHACL validation → write → type-capture) — the same enforcement path as HTTP PUT/POST. Pass a `types` array (the `Link: rel="type"` equivalent) to declare server-managed types.
@@ -114,7 +114,7 @@ Writes (`write_resource`/`create_resource`, and `put_typed_resource` below) rout
114114
| Tool | Composes |
115115
|---|---|
116116
| `put_typed_resource` | write body + capture `types` + optionally declare a `describedby` shape into the target `.meta`, in one call |
117-
| `describe_resource` | one read returning body + declared types + linkset together; takes `path` or `uri` — when both are given, `path` wins and `uri` is ignored |
117+
| `describe_resource` | one read returning body + declared types + linkset together — the linkset's `canonical`/`alternate` members carry the resource's authz-filtered `altr:` representations, and the result carries a `hint` teaching that representations are negotiable via `Accept-Profile` and alternates are listed as `rel=alternate`; takes `path` or `uri` — when both are given, `path` wins and `uri` is ignored |
118118

119119
### ACL editing
120120

‎package-lock.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"fastify": "^4.29.1",
3737
"fs-extra": "^11.2.0",
3838
"jose": "^6.1.3",
39+
"jsonld": "^9.0.0",
3940
"microfed": "^0.0.14",
4041
"mime-types": "^2.1.35",
4142
"n3": "^1.26.0",

‎src/config.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ export const defaults = {
3636
conneg: false,
3737
lws: false,
3838
lwsTypeIndex: true,
39-
lwsProfileIndex: null,
40-
// ON by default whenever --lws is on (mirrors lwsTypeIndex, not
41-
// lwsProfileIndex's opt-in-path null) — see task-6-report.md for why.
39+
// ON by default whenever --lws is on (mirrors lwsTypeIndex) — see
40+
// task-6-report.md for why.
4241
lwsProfileConneg: true,
43-
// Opt-in path, same shape as lwsProfileIndex (task-7-brief.md): the fork
44-
// only routes to a configured pod resource, never generates VoID content.
45-
lwsVoid: null,
42+
// Pod resource declaring { profileIndex, void } as data (spec §4b) —
43+
// opt-in path, read lazily + mtime-cached (src/lws/pod-config.js). Replaces
44+
// the old --lws-profile-index/--lws-void per-service flags.
45+
lwsConfig: null,
4646
notifications: false,
4747

4848
// Identity Provider
@@ -160,6 +160,10 @@ export const defaults = {
160160
// or Solid-OIDC DPoP) on /mcp — for exposing MCP to an untrusted/networked
161161
// agent rather than a trusted local one. See docs/foundations/05-jss-spec-conformance.md axis 6.
162162
mcpCredentialPolicy: 'trusted-local',
163+
// SSRF guard opt-in for the MCP federation arm (dt8, spec §6). Off by
164+
// default — readRemote refuses loopback/RFC-1918/link-local/cloud-metadata
165+
// targets. The local rig flips this to reach private targets deliberately.
166+
lwsFederationPrivate: false,
163167

164168
// Logging
165169
logger: true,
@@ -183,9 +187,8 @@ const envMap = {
183187
JSS_CONNEG: 'conneg',
184188
JSS_LWS: 'lws',
185189
JSS_LWS_TYPE_INDEX: 'lwsTypeIndex',
186-
JSS_LWS_PROFILE_INDEX: 'lwsProfileIndex',
187190
JSS_LWS_PROFILE_CONNEG: 'lwsProfileConneg',
188-
JSS_LWS_VOID: 'lwsVoid',
191+
JSS_LWS_CONFIG: 'lwsConfig',
189192
JSS_NOTIFICATIONS: 'notifications',
190193
JSS_QUIET: 'quiet',
191194
JSS_LOG_LEVEL: 'logLevel',
@@ -240,6 +243,7 @@ const envMap = {
240243
JSS_MONGO_DATABASE: 'mongoDatabase',
241244
JSS_MCP: 'mcp',
242245
JSS_MCP_CREDENTIAL_POLICY: 'mcpCredentialPolicy',
246+
JSS_LWS_FEDERATION_PRIVATE: 'lwsFederationPrivate',
243247
};
244248

245249
/**
@@ -289,6 +293,7 @@ const BOOLEAN_KEYS = new Set([
289293
'pay',
290294
'mongo',
291295
'mcp',
296+
'lwsFederationPrivate',
292297
'idp',
293298
'notifications',
294299
'logger',

‎src/handlers/container.js‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { emitChange } from '../notifications/events.js';
1111
import { constraintProblem } from '../lws/admission.js';
1212
import { parseTypeLinks } from '../lws/type-metadata.js';
1313
import { applyLwsWrite } from '../lws/write.js';
14+
import { writeTypeConsistency } from '../lws/write-consistency.js';
1415

1516
/**
1617
* Get the storage path and resource URL for a request
@@ -42,10 +43,12 @@ export async function handlePost(request, reply) {
4243
}
4344

4445
const connegEnabled = request.connegEnabled || false;
46+
// Spec §4a: --lws mandates the negotiation surface; conneg is implied by it.
47+
const negotiate = connegEnabled || request.lwsEnabled;
4548
const contentType = request.headers['content-type'] || '';
4649

4750
// Check if we can accept this input type
48-
if (!canAcceptInput(contentType, connegEnabled)) {
51+
if (!canAcceptInput(contentType, negotiate)) {
4952
const acceptValue = connegEnabled
5053
? 'application/ld+json, application/json, text/turtle, text/n3'
5154
: 'application/ld+json, application/json';
@@ -107,11 +110,18 @@ export async function handlePost(request, reply) {
107110
content = Buffer.from('');
108111
}
109112

110-
// Convert Turtle/N3 to JSON-LD if conneg enabled
113+
// Spec §2: under --lws, store the submitted bytes verbatim; enforce
114+
// write-time name/type consistency instead of converting (B1 root fix).
115+
// The FINAL resource name (container path + slug) is what must agree
116+
// with the submitted type — not the container's own path.
117+
// --lws-off keeps the byte-identical legacy Turtle/N3→JSON-LD conversion.
111118
const inputType = contentType.split(';')[0].trim().toLowerCase();
112-
if (connegEnabled && (inputType === RDF_TYPES.TURTLE || inputType === RDF_TYPES.N3)) {
119+
if (request.lwsEnabled) {
120+
const c = writeTypeConsistency({ urlPath: newUrlPath, submittedType: contentType, lwsEnabled: true });
121+
if (!c.ok) return reply.code(400).type('application/problem+json').send(JSON.stringify(c.problem, null, 2));
122+
} else if (connegEnabled && (inputType === RDF_TYPES.TURTLE || inputType === RDF_TYPES.N3)) {
113123
try {
114-
const jsonLd = await toJsonLd(content, contentType, resourceUrl, connegEnabled, { graphEnvelope: !!request.lwsEnabled });
124+
const jsonLd = await toJsonLd(content, contentType, resourceUrl, connegEnabled, { graphEnvelope: false });
115125
content = Buffer.from(JSON.stringify(jsonLd, null, 2));
116126
} catch (e) {
117127
return reply.code(400).send({
@@ -133,7 +143,7 @@ export async function handlePost(request, reply) {
133143
// L3 admission + write + type-capture via the shared LWS core (--lws-gated
134144
// inside). New member has no own .meta yet; resolveShapeUrl falls through
135145
// to the container rule.
136-
const postContentType = (connegEnabled && (inputType === RDF_TYPES.TURTLE || inputType === RDF_TYPES.N3))
146+
const postContentType = (!request.lwsEnabled && connegEnabled && (inputType === RDF_TYPES.TURTLE || inputType === RDF_TYPES.N3))
137147
? RDF_TYPES.JSON_LD : (request.headers['content-type'] || '');
138148
const declared = request.lwsEnabled ? parseTypeLinks(linkHeader) : [];
139149
const w = await applyLwsWrite({

0 commit comments

Comments
 (0)