Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: look up federated-media feature tells on a null-prototype table (#4826)

[._.]/ Adam Eivy0c59215e36b3
diff --git a/client/src/lib/federatedMediaReadiness.js b/client/src/lib/federatedMediaReadiness.js
index 29985f8094..c873851999 100644
--- a/client/src/lib/federatedMediaReadiness.js
+++ b/client/src/lib/federatedMediaReadiness.js
@@ -137,10 +137,13 @@ function verifiedState(status, now) {
// Overlap-release fallbacks, mirroring FEDERATED_MEDIA_LEGACY_FEATURE_TELL in
// server/lib/federatedMediaWire.js. A provider on the previous build advertises
// the same build-level fact per-capability instead of at the status root.
-const LEGACY_FEATURE_TELL = Object.freeze({
+// `Object.create(null)` for the same reason the server table uses it: the key
+// is a feature name off the wire, and on a normal object `'constructor'` and
+// friends resolve to inherited values rather than being absent.
+const LEGACY_FEATURE_TELL = Object.freeze(Object.assign(Object.create(null), {
lyrics: (capability) => capability?.acceptsLyrics === true,
inputAssets: (capability) => isRecord(capability?.inputAssets),
-});
+}));
/**
* Does the build that sent this status speak `feature`? Client mirror of
diff --git a/client/src/lib/federatedMediaReadiness.test.js b/client/src/lib/federatedMediaReadiness.test.js
index 17f87ec087..8c041d3faf 100644
--- a/client/src/lib/federatedMediaReadiness.test.js
+++ b/client/src/lib/federatedMediaReadiness.test.js
@@ -419,6 +419,17 @@ describe('federatedMediaSupports / peerMediaProviderSnapshot', () => {
expect(federatedMediaSupports({}, 'inputAssets', { inputAssets: [] })).toBe(false);
});
+ // Mirrors the server guard: a feature name off the wire can collide with an
+ // Object.prototype key, and both ends must answer alike rather than one
+ // returning false while the other throws.
+ it.each(['constructor', 'toString', 'hasOwnProperty', 'valueOf', '__proto__'])(
+ 'answers false for the inherited key %s instead of throwing',
+ (feature) => {
+ expect(federatedMediaSupports({}, feature, capability)).toBe(false);
+ expect(federatedMediaSupports(null, feature)).toBe(false);
+ },
+ );
+
it('returns the peer snapshot only when one is actually stored', () => {
expect(peerMediaProviderSnapshot(null)).toBeNull();
expect(peerMediaProviderSnapshot({ mediaProviderStatus: {} })).toBeNull();
diff --git a/docs/FEDERATED_MEDIA_PROVIDERS.md b/docs/FEDERATED_MEDIA_PROVIDERS.md
index 69ba13ba5d..764d92b044 100644
--- a/docs/FEDERATED_MEDIA_PROVIDERS.md
+++ b/docs/FEDERATED_MEDIA_PROVIDERS.md
@@ -427,13 +427,19 @@ absent as unknown: a provider that never shipped the handling rejects the field
at submission, so inferring consent from silence turns every such render into a
400 the user cannot act on.
-A consumer **filters** this list rather than validating it. A feature name it
-does not recognize is carried through and simply never matched; one that is not
-a short identifier token is dropped; a `features` value too malformed to filter
-at all degrades to absent. None of those invalidate the status. That matters
-more than it looks: a strict element schema would take a peer's ENTIRE status
-offline over one string, turning "ignores a feature we have not heard of" into
-"cannot read this peer" — the failure this list was introduced to prevent.
+A consumer **filters** this list rather than validating it, per member:
+
+- a feature name it does not recognize is carried through and simply never matched;
+- a member that is not a short identifier token — prose, a number, `null` — is dropped, and costs its neighbours nothing;
+- only a `features` value that is not a bounded array at all degrades to absent.
+
+None of those invalidate the status, and that matters more than it looks. A
+strict element schema fails before any filtering runs, so ONE bad string would
+take a peer's entire status offline — turning "ignores a feature we have not
+heard of" into "cannot read this peer", the failure this list was introduced to
+prevent. Degrading to absent rather than `[]` matters for the same reason: an
+empty list is a peer positively denying every feature, which is a stronger claim
+than a malformed field has earned.
Consumers ask `federatedMediaSupports(status, feature, capability)` rather than
testing the list inline, which is also where the overlap fallback to the legacy
diff --git a/server/lib/federatedMediaWire.js b/server/lib/federatedMediaWire.js
index 9aeb759a7f..5e613b07fe 100644
--- a/server/lib/federatedMediaWire.js
+++ b/server/lib/federatedMediaWire.js
@@ -374,12 +374,20 @@ const FEDERATED_MEDIA_FEATURE_RE = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;
// Dropping an out-of-shape member is also what keeps the PII bound meaningful:
// prose never reaches storage, instead of a prose-carrying payload being
// rejected wholesale after we have already read it.
-const federatedMediaFeaturesSchema = z.array(z.string()).max(256)
- .transform((features) => features.filter((feature) => FEDERATED_MEDIA_FEATURE_RE.test(feature)))
- // A `features` value that is not even a bounded array of strings degrades to
- // ABSENT — the undecidable wire-v1 baseline — rather than invalidating the
- // status. Not `[]`: an empty list is a peer positively denying every feature,
- // which is a stronger claim than a malformed field has earned.
+const federatedMediaFeaturesSchema = z.array(z.unknown()).max(256)
+ .transform((features) => features.filter((feature) => typeof feature === 'string'
+ && FEDERATED_MEDIA_FEATURE_RE.test(feature)))
+ // `z.array(z.unknown())`, not `z.array(z.string())`: a strict element type
+ // fails before the transform runs, so ONE non-string member would collapse the
+ // whole list to absent — a peer reading as supporting nothing rather than
+ // losing one entry, which is the same cliff a strict schema creates at the
+ // payload level. Filtering keeps every well-formed feature its neighbours
+ // published.
+ //
+ // A `features` value that is not even a bounded array degrades to ABSENT — the
+ // undecidable wire-v1 baseline — rather than invalidating the status. Not
+ // `[]`: an empty list is a peer positively denying every feature, a stronger
+ // claim than a malformed field has earned.
.catch(() => undefined);
// The ONE place the "absent reads as false" reasoning lives (#4826). Every
@@ -411,7 +419,12 @@ const federatedMediaFeaturesSchema = z.array(z.string()).max(256)
//
// Both gate identically; only a message that blames the BUILD may distinguish
// them. See federatedMediaDeniesFeature.
-const FEDERATED_MEDIA_LEGACY_FEATURE_TELL = Object.freeze({
+// `Object.create(null)`, not a bare literal: the lookup is keyed by a feature
+// name off the wire, and on a normal object `'constructor'` / `'toString'`
+// resolve to inherited values — truthy enough to defeat `?.` and then blow up
+// on `.tell`. A null prototype makes an unknown name simply absent, which is
+// also what keeps this end and the client mirror answering alike.
+const FEDERATED_MEDIA_LEGACY_FEATURE_TELL = Object.freeze(Object.assign(Object.create(null), {
lyrics: { tell: (capability) => capability?.acceptsLyrics === true, decisive: true },
// A build that predates conditioning omits the block entirely; one that
// speaks it advertises the block (possibly with no roles for this model).
@@ -420,7 +433,7 @@ const FEDERATED_MEDIA_LEGACY_FEATURE_TELL = Object.freeze({
// reading true here and false there is exactly the provider/consumer
// disagreement this helper exists to prevent.
inputAssets: { tell: (capability) => isPlainObject(capability?.inputAssets), decisive: false },
-});
+}));
/**
* Does the build that sent this status speak `feature`?
diff --git a/server/lib/federatedMediaWire.test.js b/server/lib/federatedMediaWire.test.js
index 9f571a1b7b..604827dd58 100644
--- a/server/lib/federatedMediaWire.test.js
+++ b/server/lib/federatedMediaWire.test.js
@@ -255,6 +255,10 @@ describe('federated media status kind projection', () => {
expect(featuresOf(['lyrics', 'a private note about the user'])).toEqual(['lyrics']);
expect(featuresOf(['lyrics', ''])).toEqual(['lyrics']);
expect(featuresOf(['lyrics', 'x'.repeat(65)])).toEqual(['lyrics']);
+ // A non-string member costs its neighbours nothing. A strict element type
+ // would fail before the filter runs and collapse the whole list to absent,
+ // reading a peer as supporting NOTHING rather than losing one entry.
+ expect(featuresOf(['lyrics', 123, null, 'inputAssets'])).toEqual(['lyrics', 'inputAssets']);
});
// A field too malformed to filter reads as ABSENT — the undecidable wire-v1
@@ -264,7 +268,7 @@ describe('federated media status kind projection', () => {
it('degrades an unusable features field to absent without failing the payload', () => {
const parsed = (features) => federatedMediaProviderStatusSchema
.safeParse(status({ features }));
- for (const bad of ['lyrics', ['lyrics', 123], Array.from({ length: 300 }, (_, i) => `f${i}`)]) {
+ for (const bad of ['lyrics', 42, { lyrics: true }, Array.from({ length: 300 }, (_, i) => `f${i}`)]) {
const result = parsed(bad);
expect(result.success).toBe(true);
expect(result.data.features).toBeUndefined();
@@ -417,11 +421,25 @@ describe('federatedMediaSupports', () => {
expect(federatedMediaDeniesFeature({}, 'inputAssets', withBlock)).toBe(false);
});
- it('exposes every feature this build emits, and answers false for anything else', () => {
+ it('exposes every feature this build emits', () => {
expect([...FEDERATED_MEDIA_FEATURES]).toEqual(['lyrics', 'inputAssets']);
for (const feature of FEDERATED_MEDIA_FEATURES) {
expect(federatedMediaSupports({ features: [...FEDERATED_MEDIA_FEATURES] }, feature)).toBe(true);
}
- expect(federatedMediaSupports({ features: ['lyrics'] }, 'constructor', capability())).toBe(false);
});
+
+ // The feature name is a string off the wire, so it can collide with an
+ // Object.prototype key. These MUST take the legacy-tell path (no `features`
+ // list) — with a list present every case short-circuits before the lookup and
+ // the guard would be vacuous. On a normal object literal `'constructor'`
+ // resolves to an inherited value, truthy enough to defeat `?.` and then throw
+ // on the property access after it.
+ it.each(['constructor', 'toString', 'hasOwnProperty', 'valueOf', '__proto__'])(
+ 'answers false for the inherited key %s instead of throwing',
+ (feature) => {
+ expect(federatedMediaSupports({}, feature, capability())).toBe(false);
+ expect(federatedMediaSupports(null, feature)).toBe(false);
+ expect(federatedMediaDeniesFeature({}, feature, capability())).toBe(false);
+ },
+ );
});