Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/composition/src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ function assertAttributes(attributes: readonly VisualAttribute[] | undefined, la
if (!/^(?:data-[a-z0-9-]+|aria-[a-z0-9-]+|role|title|lang|dir)$/u.test(attribute.name)) {
throw new Error(`${label} contains unsafe attribute ${attribute.name}.`);
}
// `data-hypit-*` attributes carry compiler-owned semantics (deferred resources, sampling
// state, element identity). Authored attributes serialize first and duplicate names keep
// the authored value, so an author could otherwise choose what the runtime promotes.
if (attribute.name.startsWith("data-hypit-")) {
throw new Error(`${label} contains reserved attribute ${attribute.name}.`);
}
if (attribute.name === "lang" && !/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/u.test(attribute.value)) {
throw new Error(`${label} contains invalid lang ${attribute.value}.`);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/composition/test/track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ test("VisualTrack style values cannot smuggle a second declaration", () => {
);
});

test("VisualTrack elements cannot claim the reserved data-hypit attribute namespace", () => {
const { timeline, visual } = fixture();
const first = visual.presents[0]!.elements[0]!;
const hostile = sealVisualTrack({...visual,
presents: [{
...visual.presents[0]!,
elements: [{ ...first, attributes: [{ name: "data-hypit-resource-src", value: "https://invalid.example/x" }] }],
}],
});
assert.throws(
() => assertVisualTrackIdentity(hostile, timeline),
/reserved attribute data-hypit-resource-src/,
);
});

test("VisualTrack cannot silently extend the versioned public Visual IR", () => {
const { timeline, visual } = fixture();
const first = visual.presents[0]!.elements[0]!;
Expand Down