Skip to content

Commit dea021d

Browse files
committed
Update hyperclayjs
1 parent 3be42c8 commit dea021d

7 files changed

Lines changed: 41 additions & 14 deletions

File tree

‎__tests__/save-token-endpoint.test.js‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jest.mock('../src/core/snapshot.js', () => ({
2727
}));
2828

2929
import { savePage, saveHtml } from '../src/core/savePageCore.js';
30-
import { SAVE_TOKEN_ATTRS, HOST_TOKEN_ATTRS } from '../src/utilities/root-attrs.js';
30+
import { SAVE_TOKEN_ATTRS, HOST_TOKEN_ATTRS, HOST_IDENTITY_ATTRS, isTabLocalRootAttr } from '../src/utilities/root-attrs.js';
3131

3232
const pathOf = (url) => new URL(url, 'http://localhost').pathname;
3333

@@ -150,18 +150,35 @@ describe('save credentials follow the endpoint', () => {
150150
});
151151

152152
describe('the token list holds nothing but tokens', () => {
153-
// This is the mistake clayjs made and is still carrying: its one list serves both
154-
// the token-resolution job and the morph-protection job, so `htmlclayid` was
155-
// appended for the second and silently became a credential for the first. Any
156-
// name in SAVE_TOKEN_ATTRS is returned by saveToken() and put straight into the
157-
// save URL, so a durable per-file identity in here would be posted as if it were
158-
// a credential. Keep the guard structural rather than a comment: clayjs has the
159-
// comment.
153+
// Any name in SAVE_TOKEN_ATTRS is returned by saveToken() and put straight into
154+
// the save URL, so a durable per-file identity in here would be posted as if it
155+
// were a credential. clayjs hit exactly that: one list served both the
156+
// token-resolution job and the morph-protection job, `htmlclayid` was appended
157+
// for the second, and it silently became a credential for the first. Both
158+
// libraries now keep two lists. Keep the guard structural rather than a comment.
160159
test('SAVE_TOKEN_ATTRS carries no durable identity attribute', () => {
161160
expect(SAVE_TOKEN_ATTRS).not.toContain('htmlclayid');
162161
expect(SAVE_TOKEN_ATTRS).not.toContain('documentid');
163162
});
164163

164+
// The identity still needs the morph protection, under both spellings. htmlclay
165+
// serves `documentid` and reads either, and every file saved before that rename
166+
// holds `htmlclayid` on disk forever, so a list that knows one name leaves the
167+
// other unprotected: an incoming frame strips this tab's copy.
168+
test('both identity spellings are protected from a peer morph', () => {
169+
for (const name of ['documentid', 'htmlclayid']) {
170+
expect(HOST_IDENTITY_ATTRS).toContain(name);
171+
expect(HOST_TOKEN_ATTRS).toContain(name);
172+
expect(isTabLocalRootAttr(name, document.documentElement)).toBe(true);
173+
}
174+
});
175+
176+
// The order is the contract for any reader taking the first name it finds: a
177+
// document carrying both must resolve to the current one.
178+
test('the current identity spelling is read first', () => {
179+
expect(HOST_IDENTITY_ATTRS[0]).toBe('documentid');
180+
});
181+
165182
test('a durable identity in the DOM is never mistaken for a token', async () => {
166183
document.documentElement.setAttribute('htmlclayid', 'DURABLE-UUID');
167184

‎conformance/fixtures/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Conformance fixtures — canonical home
22

3-
These are the canonical Malleable HTML File conformance fixtures (spec §11). They are
3+
These are the canonical Malleable HTML File conformance fixtures (spec §12). They are
44
the published arbiter of exact bytes: a conforming client must reproduce each fixture's
55
`snapshot.html` and `document.html` byte-for-byte from its `input.html`.
66

‎conformance/fixtures/sync-root-attrs/document.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html><html lang="en" savetoken="ephemeral-abc123" htmlclaytoken="ephemeral-def456" documentid="durable-xyz789" savestatus="unsaved" editmode="true" pageowner="true"><head>
1+
<!DOCTYPE html><html lang="en" savetoken="ephemeral-abc123" htmlclaytoken="ephemeral-def456" documentid="durable-xyz789" htmlclayid="pre-spec-uuid" data-doc-version="7" savestatus="unsaved" editmode="true" pageowner="true"><head>
22
<meta charset="utf-8">
33
<title>Sync payload root attributes</title>
44
</head>

‎conformance/fixtures/sync-root-attrs/input.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en" savetoken="ephemeral-abc123" htmlclaytoken="ephemeral-def456" documentid="durable-xyz789">
2+
<html lang="en" savetoken="ephemeral-abc123" htmlclaytoken="ephemeral-def456" documentid="durable-xyz789" htmlclayid="pre-spec-uuid" data-doc-version="7">
33
<head>
44
<meta charset="utf-8">
55
<title>Sync payload root attributes</title>

‎conformance/fixtures/sync-root-attrs/snapshot.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html><html lang="en" savetoken="ephemeral-abc123" htmlclaytoken="ephemeral-def456" documentid="durable-xyz789" savestatus="unsaved" editmode="true" pageowner="true"><head>
1+
<!DOCTYPE html><html lang="en" savetoken="ephemeral-abc123" htmlclaytoken="ephemeral-def456" documentid="durable-xyz789" htmlclayid="pre-spec-uuid" data-doc-version="7" savestatus="unsaved" editmode="true" pageowner="true"><head>
22
<meta charset="utf-8">
33
<title>Sync payload root attributes</title>
44
</head>

‎conformance/fixtures/sync-root-attrs/sync.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html lang="en" documentid="durable-xyz789"><head>
1+
<html lang="en" data-doc-version="7"><head>
22
<meta charset="utf-8">
33
<title>Sync payload root attributes</title>
44
</head>

‎src/utilities/root-attrs.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ export const SAVE_TOKEN_ATTRS = ["savetoken", "htmlclaytoken"];
2525
// But §9 bounds only the save path, and §10 fans a snapshot out to other editors'
2626
// browsers, which is the hole this module closes.
2727
//
28+
// The durable per-file identity, in the spec's spelling and the pre-spec one, in
29+
// the order a reader tries them. Host-injected but NOT a credential, which is why
30+
// it lives here and not in SAVE_TOKEN_ATTRS: putting it there would make this
31+
// library POST to /_/save/{id} whenever a host minted no token of its own.
32+
//
33+
// Both spellings are permanent. htmlclay serves `documentid` and reads either, but
34+
// every .htmlclay file saved before that rename holds `htmlclayid` on disk forever,
35+
// and this list is what a morph consults.
36+
export const HOST_IDENTITY_ATTRS = ["documentid", "htmlclayid"];
37+
2838
// Derived from SAVE_TOKEN_ATTRS so the two lists can never disagree about the
2939
// token spellings, and kept separate so a durable identity attribute can join the
3040
// morph protection without also becoming a save credential.
31-
export const HOST_TOKEN_ATTRS = [...SAVE_TOKEN_ATTRS];
41+
export const HOST_TOKEN_ATTRS = [...SAVE_TOKEN_ATTRS, ...HOST_IDENTITY_ATTRS];
3242

3343
// This library's own root state, and this tab's UI truth.
3444
export const ROOT_LIBRARY_ATTRS = ["savestatus", "editmode", "pageowner"];

0 commit comments

Comments
 (0)