@full-self-browsing/phantom-stream 0.1.0 → 0.2.1
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.
- package/dist/types/adapters/extension.d.ts.map +1 -1
- package/dist/types/adapters/playwright.d.ts.map +1 -1
- package/dist/types/capture/index.d.ts +112 -0
- package/dist/types/capture/index.d.ts.map +1 -1
- package/dist/types/protocol/constants.d.ts +22 -0
- package/dist/types/protocol/constants.d.ts.map +1 -1
- package/dist/types/protocol/index.d.ts +1 -0
- package/dist/types/protocol/media-reconcile.d.ts +53 -0
- package/dist/types/protocol/media-reconcile.d.ts.map +1 -0
- package/dist/types/protocol/messages.d.ts +266 -2
- package/dist/types/protocol/messages.d.ts.map +1 -1
- package/dist/types/renderer/asset-policy.d.ts +72 -0
- package/dist/types/renderer/asset-policy.d.ts.map +1 -0
- package/dist/types/renderer/diff.d.ts.map +1 -1
- package/dist/types/renderer/index.d.ts +13 -0
- package/dist/types/renderer/index.d.ts.map +1 -1
- package/dist/types/renderer/media-player.d.ts +114 -0
- package/dist/types/renderer/media-player.d.ts.map +1 -0
- package/dist/types/renderer/overlays.d.ts +12 -0
- package/dist/types/renderer/overlays.d.ts.map +1 -1
- package/dist/types/renderer/sanitize.d.ts +22 -0
- package/dist/types/renderer/sanitize.d.ts.map +1 -1
- package/dist/types/renderer/snapshot.d.ts +38 -0
- package/dist/types/renderer/snapshot.d.ts.map +1 -1
- package/dist/types/transport/websocket.d.ts.map +1 -1
- package/docs/ARCHITECTURE.md +13 -4
- package/docs/SECURITY.md +233 -2
- package/examples/bookmarklet-demo/viewer.html +12 -3
- package/examples/extension-mv3/viewer.html +10 -3
- package/package.json +9 -1
- package/src/adapters/extension.js +202 -7
- package/src/adapters/playwright-inject.js +50 -0
- package/src/adapters/playwright.js +159 -0
- package/src/capture/index.js +1071 -11
- package/src/protocol/constants.js +24 -0
- package/src/protocol/index.js +1 -0
- package/src/protocol/media-reconcile.js +188 -0
- package/src/protocol/messages.js +145 -2
- package/src/renderer/asset-policy.js +172 -0
- package/src/renderer/diff.js +106 -2
- package/src/renderer/index.js +849 -9
- package/src/renderer/media-player.js +367 -0
- package/src/renderer/overlays.js +324 -0
- package/src/renderer/sanitize.js +25 -3
- package/src/renderer/snapshot.js +534 -3
- package/src/transport/websocket.js +36 -0
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The renderer's pre-write asset fetch gate (MSEC-01/MSEC-02). Pure: decides
|
|
3
|
+
* allow/deny for a single asset URL under the posture carried in ctx. Every
|
|
4
|
+
* branch that is not an explicit allow fails closed.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url Absolute asset URL about to be written into the mirror.
|
|
7
|
+
* @param {Object} [ctx] Posture: { mediaMode, allowAssetOrigins, assetOriginPolicy, kind }.
|
|
8
|
+
* @returns {{ allow: boolean, reason: string }}
|
|
9
|
+
*/
|
|
10
|
+
export function gateAssetUrl(url: string, ctx?: any): {
|
|
11
|
+
allow: boolean;
|
|
12
|
+
reason: string;
|
|
13
|
+
};
|
|
1
14
|
/**
|
|
2
15
|
* The host-injected viewer transport. Mirrors the capture Transport's
|
|
3
16
|
* fire-and-forget send contract and adds the receive side; Phase 4's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/renderer/index.js"],"names":[],"mappings":"AA6GA;;;;;;;;GAQG;AACH,kCAJW,MAAM,cAEJ;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAsD9C;AAED;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;;;;GAYG;AACH,oCANW,MAAM,SACN,MAAM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OAAO;;;;oBAG3D,MAAM,IAAI;;;;;;oBAEV,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,MAAM,GAAC,IAAI;;;;;qBAIhE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAC,EAAE,UAAU,EAAE,UAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI;;;;QAG3F,CAAC,SAAS,EAAE,OAAO,GAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,KAAK,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create the parent-realm adaptive media player. The renderer injects the live
|
|
3
|
+
* deps in Plan 03; the Plan 02 tests inject stubs/fakes (a stub `win` carrying
|
|
4
|
+
* MediaSource, a controllable-canPlayType video stub, a fake playerFactory, and
|
|
5
|
+
* a `tryLazyImportHls` override). Maintains a per-nid registry so a re-snapshot
|
|
6
|
+
* (Plan 03) can destroyAll() before the new mirror document replaces the child
|
|
7
|
+
* elements (Pattern 2 -- player teardown on new identity).
|
|
8
|
+
*
|
|
9
|
+
* @param {MediaPlayerDeps} deps
|
|
10
|
+
* @returns {{
|
|
11
|
+
* attach: (videoEl: HTMLMediaElement, manifestUrl: string, ctx?: Object) => (Object|Promise<Object|undefined>|undefined),
|
|
12
|
+
* degrade: (nid: ?string, reason: string) => undefined,
|
|
13
|
+
* destroy: (nid: ?string) => undefined,
|
|
14
|
+
* destroyAll: () => undefined
|
|
15
|
+
* }}
|
|
16
|
+
*/
|
|
17
|
+
export function createMediaPlayer(deps: MediaPlayerDeps): {
|
|
18
|
+
attach: (videoEl: HTMLMediaElement, manifestUrl: string, ctx?: any) => (any | Promise<any | undefined> | undefined);
|
|
19
|
+
degrade: (nid: string | null, reason: string) => undefined;
|
|
20
|
+
destroy: (nid: string | null) => undefined;
|
|
21
|
+
destroyAll: () => undefined;
|
|
22
|
+
};
|
|
23
|
+
export type PlayerAdapterCtx = {
|
|
24
|
+
/**
|
|
25
|
+
* iframe.contentDocument (where videoEl lives)
|
|
26
|
+
*/
|
|
27
|
+
doc: Document;
|
|
28
|
+
/**
|
|
29
|
+
* gated, absolute manifest URL
|
|
30
|
+
*/
|
|
31
|
+
manifestUrl: string;
|
|
32
|
+
/**
|
|
33
|
+
* derived from the manifest classifier
|
|
34
|
+
*/
|
|
35
|
+
kind: "hls" | "dash";
|
|
36
|
+
/**
|
|
37
|
+
* the in-iframe child element
|
|
38
|
+
*/
|
|
39
|
+
videoEl: HTMLMediaElement;
|
|
40
|
+
logger: any;
|
|
41
|
+
/**
|
|
42
|
+
* reuse Phase 12 gate
|
|
43
|
+
*/
|
|
44
|
+
gateAsset: (url: string, kind: string) => {
|
|
45
|
+
allow: boolean;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* element nid for overlay anchoring + the reason callback
|
|
49
|
+
*/
|
|
50
|
+
nid: string | null;
|
|
51
|
+
};
|
|
52
|
+
export type PlayerAdapter = {
|
|
53
|
+
/**
|
|
54
|
+
* Bind the manifest to the element (host owns MSE/attachMedia/segment fetch in the PARENT realm).
|
|
55
|
+
*/
|
|
56
|
+
attach: (videoEl: HTMLMediaElement, manifestUrl: string, ctx: PlayerAdapterCtx) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Tear down: detach MSE, revoke object URLs, free buffers. Idempotent.
|
|
59
|
+
*/
|
|
60
|
+
destroy: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* Report a fatal/unrecoverable error with a reason code; the viewer degrades to poster.
|
|
63
|
+
*/
|
|
64
|
+
onError?: (handler: (reason: string) => void) => void;
|
|
65
|
+
};
|
|
66
|
+
export type MediaPlayerDeps = {
|
|
67
|
+
/**
|
|
68
|
+
* iframe.contentDocument the child <video> lives in
|
|
69
|
+
*/
|
|
70
|
+
doc: Document;
|
|
71
|
+
/**
|
|
72
|
+
* the PARENT realm window (MSE feature-detect surface)
|
|
73
|
+
*/
|
|
74
|
+
win: Window;
|
|
75
|
+
/**
|
|
76
|
+
* Phase 12 fail-closed gate
|
|
77
|
+
*/
|
|
78
|
+
gateAsset: (url: string, kind: string) => {
|
|
79
|
+
allow: boolean;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* viewer logger (info/warn/error)
|
|
83
|
+
*/
|
|
84
|
+
logger: any;
|
|
85
|
+
/**
|
|
86
|
+
* host-provided player seam
|
|
87
|
+
*/
|
|
88
|
+
playerFactory?: (ctx: PlayerAdapterCtx) => PlayerAdapter;
|
|
89
|
+
/**
|
|
90
|
+
* degrade reason callback
|
|
91
|
+
*/
|
|
92
|
+
onMediaUnavailable: (nid: string | null, reason: string) => void;
|
|
93
|
+
/**
|
|
94
|
+
* overlay driver
|
|
95
|
+
*/
|
|
96
|
+
showOverlay: (kind: string, payload: any | null, ctx: any | null) => void;
|
|
97
|
+
/**
|
|
98
|
+
* anchor-rect resolver for the overlay
|
|
99
|
+
*/
|
|
100
|
+
resolveNidRect: (nid: string | null) => any | null;
|
|
101
|
+
/**
|
|
102
|
+
* Phase 13 play kickoff
|
|
103
|
+
*/
|
|
104
|
+
ensurePlaying: (videoEl: HTMLMediaElement, nid: string | null) => void;
|
|
105
|
+
/**
|
|
106
|
+
* keep/restore the element poster on degrade
|
|
107
|
+
*/
|
|
108
|
+
keepPoster?: (nid: string | null) => void;
|
|
109
|
+
/**
|
|
110
|
+
* TEST SEAM: override the dynamic hls.js import
|
|
111
|
+
*/
|
|
112
|
+
tryLazyImportHls?: () => Promise<any>;
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=media-player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-player.d.ts","sourceRoot":"","sources":["../../../src/renderer/media-player.js"],"names":[],"mappings":"AA8HA;;;;;;;;;;;;;;;GAe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AAO,EAAE,gBAAgB,EAAE,GAAG,EAAG,MAAM,OAAA,KAAK,IAAI;;;;iBACjD,CAAC,GAAG,EAAG,MAAM,OAAA,KAAK,IAAI;;;;uBACtB,MAAM,OAAO,CAAC,GAAC,CAAC"}
|
|
@@ -81,6 +81,10 @@ export function mapHostPointToViewport(point: {
|
|
|
81
81
|
* Dispatch one STREAM.OVERLAY payload through the registry.
|
|
82
82
|
* @property {(payload: Object) => void} handleDialogMessage
|
|
83
83
|
* STREAM.DIALOG handler (dialog card show/hide).
|
|
84
|
+
* @property {(kind: string, payload: ?Object, ctx?: {anchorRect?: ?Object}) => void} show
|
|
85
|
+
* Drive a registered overlay kind directly from renderer state (the media
|
|
86
|
+
* affordances are renderer-state-driven, not wire-driven; 13-UI-SPEC). ctx
|
|
87
|
+
* carries the pre-resolved anchorRect. A null payload hides (reset contract).
|
|
84
88
|
* @property {() => void} resetOverlays
|
|
85
89
|
* Hide all kinds (new-snapshot reset, dashboard.js:2762-2764 parity).
|
|
86
90
|
*/
|
|
@@ -158,6 +162,14 @@ export type OverlaysHandle = {
|
|
|
158
162
|
* STREAM.DIALOG handler (dialog card show/hide).
|
|
159
163
|
*/
|
|
160
164
|
handleDialogMessage: (payload: any) => void;
|
|
165
|
+
/**
|
|
166
|
+
* Drive a registered overlay kind directly from renderer state (the media
|
|
167
|
+
* affordances are renderer-state-driven, not wire-driven; 13-UI-SPEC). ctx
|
|
168
|
+
* carries the pre-resolved anchorRect. A null payload hides (reset contract).
|
|
169
|
+
*/
|
|
170
|
+
show: (kind: string, payload: any | null, ctx?: {
|
|
171
|
+
anchorRect?: any | null;
|
|
172
|
+
}) => void;
|
|
161
173
|
/**
|
|
162
174
|
* Hide all kinds (new-snapshot reset, dashboard.js:2762-2764 parity).
|
|
163
175
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlays.d.ts","sourceRoot":"","sources":["../../../src/renderer/overlays.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":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AAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC;;;;;;oBAE7C,CAAC,GAAG,EAAE,MAAM,GAAC,MAAM,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAC,IAAI,CAAC;;;;;;;;;;;WASzF,OAAO;;;;;cAIP,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAC,EAAE,UAAU,EAAE,UAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,KAAK,IAAI;;;;0BAG3F,CAAC,OAAO,KAAQ,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI;;;;yBAE9C,CAAC,OAAO,KAAQ,KAAK,IAAI;;;;;;UAEzB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAO,EAAE,GAAG,CAAC,EAAE;QAAC,UAAU,CAAC,EAAE,UAAO,CAAA;KAAC,KAAK,IAAI;;;;mBAItE,MAAM,IAAI"}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal srcset candidate parser for the URL+descriptor forms this project
|
|
3
|
+
* emits (mirror of the capture-side parser). Unlike split(','), it keeps
|
|
4
|
+
* commas inside a candidate URL attached to the URL token, so a benign
|
|
5
|
+
* candidate cannot turn into a bogus relative fetch candidate. Two carve-outs
|
|
6
|
+
* suppress the comma-as-separator split: (1) data:image URLs (a base64 comma /
|
|
7
|
+
* the data: mediatype comma), and (2) any scheme-bearing absolute URL
|
|
8
|
+
* (http(s)/etc.), because an unencoded comma in an http(s) query string would
|
|
9
|
+
* otherwise mis-split a legitimate responsive CDN URL into a bogus second
|
|
10
|
+
* candidate -- which then fails the fetch gate and over-blocks the whole <img>
|
|
11
|
+
* to a placeholder (review WR-02). This is a fidelity widening only; the gate
|
|
12
|
+
* decision per candidate is unchanged. Exported so the Phase-12 renderer fetch
|
|
13
|
+
* gates (diff ATTR branch, gateFragmentAssets, the snapshot string layer) gate
|
|
14
|
+
* srcset per-candidate through ONE parser and the attribute coverage cannot
|
|
15
|
+
* drift between sites (review WR-03/WR-04).
|
|
16
|
+
* @param {string} srcset
|
|
17
|
+
* @returns {{url: string, descriptor: string}[]}
|
|
18
|
+
*/
|
|
19
|
+
export function parseSrcsetCandidates(srcset: string): {
|
|
20
|
+
url: string;
|
|
21
|
+
descriptor: string;
|
|
22
|
+
}[];
|
|
1
23
|
/**
|
|
2
24
|
* Targeted CSS value scrub -- the only string-operation pass in the render
|
|
3
25
|
* pipeline, and it is a VALUE scrub (regex), never a parser. Same policy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/renderer/sanitize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/renderer/sanitize.js"],"names":[],"mappings":"AA+FA;;;;;;;;;;;;;;;;;GAiBG;AACH,8CAHW,MAAM,GACJ;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,EAAE,CA4B/C;AA8BD;;;;;;;;;;;;;;;;;GAiBG;AACH,kCAHW,GAAC,GACC,MAAM,CA4BlB;AAED;;;;;;;;;GASG;AACH,wCAJW,GAAC,SACD,GAAC,GACC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,GAAC,IAAI,CAAA;CAAC,CAyB/C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,uCANW,gBAAgB,GAAC,OAAO,GAAC,IAAI,aAC7B,gBAAgB,WAEhB;IAAC,IAAI,EAAE,IAAS,IAAI,EAAD,GAAC,EAAA,KAAG,IAAI,CAAA;CAAC,GAC1B,IAAI,CAyHhB;;;;;sBApVa,MAAM;;;;iBACN,MAAM;;;;qBACN,MAAM;;;;eACN,MAAM"}
|
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite fetchable <img> assets in a raw snapshot HTML string against an
|
|
3
|
+
* injected pre-write fetch gate (MSEC-01) and apply the ASST-03 currentSrc
|
|
4
|
+
* pin. For each <img>:
|
|
5
|
+
* 1. currentSrc pin: if data-ps-currentsrc is present, the effective src
|
|
6
|
+
* becomes that value and srcset/sizes are neutralized (removed) so the
|
|
7
|
+
* cross-origin viewer's DPR cannot re-negotiate a different variant.
|
|
8
|
+
* 2. fetch gate: gate(effectiveSrc, 'image') and gate every srcset
|
|
9
|
+
* candidate; if blocked, the entire <img> is replaced by the dimensioned
|
|
10
|
+
* blocked-origin placeholder (or srcset is stripped when an allowed src
|
|
11
|
+
* remains) so the parser never sees a fetchable blocked URL.
|
|
12
|
+
* An <img> with no src/currentsrc/srcset is left untouched.
|
|
13
|
+
*
|
|
14
|
+
* QUOTE-AWARE TAG SCAN (review CR-02): every start tag is located with a
|
|
15
|
+
* quote-aware scanner (findTagEnd), NOT a `[^>]*` regex -- a `>` inside a
|
|
16
|
+
* quoted attribute value (`alt="a>b"`) does not terminate the tag, so a
|
|
17
|
+
* blocked `src` after such a `>` can no longer slip through unmodified. An
|
|
18
|
+
* opener whose tag end cannot be located (an unbalanced quote running to EOF)
|
|
19
|
+
* is FAILED CLOSED: it is replaced by the dimensioned placeholder rather than
|
|
20
|
+
* passed through, so a malformed shape can never emit a fetchable blocked URL.
|
|
21
|
+
* The gate is fail-closed by construction (createViewer's gateAssetUrl); a
|
|
22
|
+
* missing gate leaves the markup unchanged (no-op) so this stays a pure string
|
|
23
|
+
* transform.
|
|
24
|
+
*
|
|
25
|
+
* PHASE 13 MEDIA GENERALIZATION (MEDIA-01 / V12): the scan now covers <img>
|
|
26
|
+
* (src/srcset + currentSrc pin), <video> (src + poster), and <source> (src) in
|
|
27
|
+
* ONE left-to-right pass -- at each cursor it advances to the nearest of the
|
|
28
|
+
* three openers and gates that tag, so a blocked media URL is neutralized at
|
|
29
|
+
* the string layer BEFORE the srcdoc parser can prefetch it (13-RESEARCH
|
|
30
|
+
* Pitfall 5). Nesting (<source> inside <video>) is handled naturally: the
|
|
31
|
+
* openers are independent matches, so each is gated on its own.
|
|
32
|
+
* @param {string} html Raw payload.html (string layer, pre-srcdoc).
|
|
33
|
+
* @param {(url: string, kind: string) => { allow: boolean }} gate
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function gateSnapshotAssets(html: string, gate: (url: string, kind: string) => {
|
|
37
|
+
allow: boolean;
|
|
38
|
+
}): string;
|
|
1
39
|
/**
|
|
2
40
|
* Escape a value for inclusion inside a double-quoted HTML attribute.
|
|
3
41
|
* Renamed port of escapePreviewAttribute (dashboard.js:2671-2677): null and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/renderer/snapshot.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/renderer/snapshot.js"],"names":[],"mappings":"AAoaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,yCAJW,MAAM,QACN,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAC/C,MAAM,CA4DlB;AAkGD;;;;;;;GAOG;AACH,uCAHW,GAAC,GACC,MAAM,CAQlB;AAED;;;;;;;;;;GAUG;AACH,iDAJW,MAAO,IAAI,GAAC,SAAS,aACrB,MAAM,GAAC,IAAI,GAAC,SAAS,GACnB,MAAM,CAiBlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,2CAHW,eAAe,GACb,MAAM,CA0ClB;AAED,8DAmBC;8BAprBa,OAAO,yBAAyB,EAAE,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/transport/websocket.js"],"names":[],"mappings":"AA8LA;;;;;;GAMG;AACH,4DAFa,OAAO,CAAC,MAAM,CAAC,CA4B3B;AAED;;;;;;GAMG;AACH,uCAJW,MAAM,GAAC,WAAW,GAAC,eAAe,GAAC,IAAI,kBAErC,OAAO,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,MAAQ;CAAC,GAAG;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC,CAmDzE;AAgCD;;;;;;;;;;;;GAYG;AACH,wDATa;IACR,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,CAAC;IAC9C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9E,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,SAAS,EAAE,SAAY,CAAA;CACxB,
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/transport/websocket.js"],"names":[],"mappings":"AA8LA;;;;;;GAMG;AACH,4DAFa,OAAO,CAAC,MAAM,CAAC,CA4B3B;AAED;;;;;;GAMG;AACH,uCAJW,MAAM,GAAC,WAAW,GAAC,eAAe,GAAC,IAAI,kBAErC,OAAO,CAAC;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,MAAQ;CAAC,GAAG;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC,CAmDzE;AAgCD;;;;;;;;;;;;GAYG;AACH,wDATa;IACR,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,CAAC;IAC9C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9E,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,KAAQ,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,SAAS,EAAE,SAAY,CAAA;CACxB,CAwQH"}
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -266,8 +266,17 @@ explicit browser/security boundaries or intentional default-mode tradeoffs:
|
|
|
266
266
|
object/embed/script-like subtrees, and hostile CSS before mirrored content is
|
|
267
267
|
transported or inserted. This is still a framework-maintained blocklist, so the
|
|
268
268
|
viewer iframe remains sandboxed without `allow-scripts` as defense in depth.
|
|
269
|
-
6. **Open shadow DOM and same-origin iframes resolved in standalone Phase 8
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
6. **Open shadow DOM and same-origin iframes resolved in standalone Phase 8;
|
|
270
|
+
`<video>`/`<audio>` mirrored by reference across the v2.0 milestone.** Media
|
|
271
|
+
is no longer a blanket non-captured boundary: `<video>`/`<audio>` are now
|
|
272
|
+
mirrored **by reference** -- playback state from the snapshot baseline,
|
|
273
|
+
progressive (direct) playback, and best-effort adaptive (HLS/DASH) playback
|
|
274
|
+
driven from a parent-realm surface -- and the media bytes never cross the
|
|
275
|
+
relay. The residual media limits narrow to three cases: DRM/EME-protected
|
|
276
|
+
content, which is unshareable by design and degrades to a poster;
|
|
277
|
+
MSE/`blob:` media with no discoverable manifest, whose origin-local object
|
|
278
|
+
URL is dead at the viewer and degrades to a poster; and raw media
|
|
279
|
+
pixels/frames, which are out of scope because PhantomStream mirrors media
|
|
280
|
+
by reference, not by pixel. Closed shadow roots and cross-origin iframe
|
|
281
|
+
content remain the standing browser security boundaries; the framework
|
|
273
282
|
documents them as non-captured content rather than faking or bypassing them.
|
package/docs/SECURITY.md
CHANGED
|
@@ -109,7 +109,9 @@ on the wire in raw form.
|
|
|
109
109
|
- `maskInputs: true` masks input, textarea, and related form value surfaces.
|
|
110
110
|
- `maskTextSelector` masks text owned by matching elements and descendants. The default transform
|
|
111
111
|
replaces each non-whitespace character with `*`, preserving whitespace and length.
|
|
112
|
-
- `blockSelector` emits a placeholder box
|
|
112
|
+
- `blockSelector` emits a placeholder box carrying only the `rr_width` and `rr_height` dimension
|
|
113
|
+
attributes -- no `data-fsb-nid`, no other attributes, no children, no text. Identity travels
|
|
114
|
+
positionally in the `nodeIds` sidecar, never as a page-visible attribute on the placeholder.
|
|
113
115
|
Attributes, children, and text from the blocked subtree are not serialized.
|
|
114
116
|
- Invalid selectors fail at factory time with `invalid-mask-selector` instead of silently falling
|
|
115
117
|
back to an unsafe state.
|
|
@@ -121,6 +123,96 @@ on the wire in raw form.
|
|
|
121
123
|
- `select` / `option` display text remains a known privacy boundary: value masking does not make
|
|
122
124
|
option labels private unless they are also covered by `maskTextSelector` or `blockSelector`.
|
|
123
125
|
|
|
126
|
+
### Asset and media URL masking (MSEC-03)
|
|
127
|
+
|
|
128
|
+
v2.0 mirrors images and `<video>` / `<audio>` **by reference** -- the wire carries URL strings and
|
|
129
|
+
small playback state, and the viewer fetches the bytes (see §6). A signed-CDN URL can therefore
|
|
130
|
+
carry credential/PII query params, and a media element's URL plus playback timeline can itself be
|
|
131
|
+
private. Three host masking options, all validated at factory time alongside the existing
|
|
132
|
+
selector family, redact or block those URLs **capture-side, before transport** -- the wire is
|
|
133
|
+
already clean and the renderer never un-masks. URL masking lives in one place: a dedicated
|
|
134
|
+
`'asset-url'` / `'media-url'` dispatch in `sanitizeForWire`, so every **single-URL** attribute
|
|
135
|
+
(the `src`, `href`, `action`, `poster`, `data` set) across the snapshot, iframe, and added-node
|
|
136
|
+
serialization paths plus the mutation attr path routes through the same testable helper.
|
|
137
|
+
|
|
138
|
+
The built-in `maskAssetUrls` token-param strip applies to those single-URL attributes only.
|
|
139
|
+
**`srcset` candidate lists are NOT token-masked by the boolean.** A `srcset` value is
|
|
140
|
+
scheme-scrubbed per candidate (`scrubSrcset` neutralizes a hostile `javascript:` / `data:text/html`
|
|
141
|
+
candidate) and absolutified, but its candidate URLs do not flow through the token-param strip, so a
|
|
142
|
+
token in a responsive candidate (`srcset="https://cdn/x.jpg?X-Amz-Signature=... 2x"`) would survive
|
|
143
|
+
`maskAssetUrls: true`. To redact srcset tokens, either match the element with `maskMediaSelector`
|
|
144
|
+
(which omits the whole element's URLs and degrades it to the dimensioned placeholder) or use
|
|
145
|
+
`maskAssetUrlFn` per element; the boolean's name-keyed query strip is single-URL-attribute scoped
|
|
146
|
+
by design.
|
|
147
|
+
|
|
148
|
+
- `maskMediaSelector` -- a CSS selector. A matched media/asset element **omits its URL from the
|
|
149
|
+
wire and degrades to the dimensioned placeholder** (the `blockSelector` path: a dimension-only
|
|
150
|
+
box carrying just `rr_width` + `rr_height`, with no `data-fsb-nid`, no other attributes, no
|
|
151
|
+
children, and no text -- identity travels in the `nodeIds` sidecar). It also reuses the
|
|
152
|
+
media-tracker skip predicates, so a masked `<video>` / `<audio>` emits **no `STREAM.MEDIA`**
|
|
153
|
+
baseline and **no `STREAM.MEDIA`** events -- neither its URL nor its playback timeline is
|
|
154
|
+
mirrored.
|
|
155
|
+
- `maskAssetUrls` -- a boolean. When `true`, every asset/media URL is parsed and its **token / PII
|
|
156
|
+
query params are stripped** before it goes on the wire; functional params are **preserved (not
|
|
157
|
+
stripped)**. It is **off by default**, so with masking disabled asset/media URLs stay
|
|
158
|
+
**byte-identical** on the wire (the differential oracle is preserved, no new ledger entry).
|
|
159
|
+
Byte-identity is guaranteed only on the no-strip path: when a URL has no denied param the
|
|
160
|
+
original string is returned **unchanged** (no `URL.toString()`, so no normalization), which is
|
|
161
|
+
also what keeps the off-by-default oracle intact. When a denied param **is** removed the URL is
|
|
162
|
+
re-serialized via `URL.toString()`, so the surviving functional params are preserved
|
|
163
|
+
*semantically* but the string may be normalized equivalently (`%20` -> `+`, host lowercased,
|
|
164
|
+
a default `:443` / `:80` dropped, percent-encoding canonicalized). This re-encode decodes to the
|
|
165
|
+
same bytes server-side -- it is not a fetch break -- but it is a wire divergence, so "survives
|
|
166
|
+
byte-for-byte" holds only for URLs that carried no denied param.
|
|
167
|
+
- `maskAssetUrlFn(url, ctx) => string | null` -- a custom redactor with full host control. A
|
|
168
|
+
returned string replaces the URL; `null` **blocks** the URL (placeholder); and a **thrown error
|
|
169
|
+
fails closed -- the URL is blocked** (not raised, never passed raw). This is stricter than the
|
|
170
|
+
text mask functions (whose fallback is the default asterisk mask) because a thrown URL redactor
|
|
171
|
+
is an undecided-unsafe URL, which must not be fetched. `ctx` carries the element/attr/tag/nid so
|
|
172
|
+
the host can decide per asset.
|
|
173
|
+
|
|
174
|
+
The `maskAssetUrls` strip removes only **credential / signature / expiry / secret** params; it is
|
|
175
|
+
matched **case-insensitively**, by **exact name OR a denied prefix**. Functional params (`w`, `h`,
|
|
176
|
+
`q`, `format`, `v`, `id`, a `?t=` seek timestamp, etc.) are never stripped -- though on a URL where
|
|
177
|
+
some other param *is* stripped they ride along through the `URL.toString()` re-serialization and
|
|
178
|
+
may come back equivalently re-encoded (see the `maskAssetUrls` bullet above). The documented
|
|
179
|
+
denylist:
|
|
180
|
+
|
|
181
|
+
| Source | Param names |
|
|
182
|
+
|---|---|
|
|
183
|
+
| AWS S3 / CloudFront presigned (SigV4) | `X-Amz-Signature`, `X-Amz-Credential`, `X-Amz-Security-Token`, `X-Amz-Algorithm`, `X-Amz-Date`, `X-Amz-Expires`, `X-Amz-SignedHeaders`, plus the `x-amz-` *prefix* family |
|
|
184
|
+
| AWS S3 / CloudFront presigned (SigV2 / canned policy) | `AWSAccessKeyId`, `Signature`, `Expires`, `Policy`, `Key-Pair-Id` |
|
|
185
|
+
| Google Cloud Storage signed URL | `X-Goog-Signature`, `X-Goog-Credential`, `X-Goog-Algorithm`, `X-Goog-Date`, `X-Goog-Expires`, `X-Goog-SignedHeaders`, `GoogleAccessId`, plus the `x-goog-` *prefix* family |
|
|
186
|
+
| Azure Blob SAS | `sig`, `se`, `sp`, `sv`, `sr`, `st`, `skoid`, `sktid`, `skt`, `ske`, `sks`, `skv`, `spr`, `sip`, `ss`, `srt` |
|
|
187
|
+
| Generic token / secret / auth | `token`, `access_token`, `auth`, `authorization`, `apikey`, `api_key`, `key`, `signature`, `sign`, `hash`, `hmac`, `jwt`, `password`, `passwd`, `pwd`, `secret`, `session`, `sessionid`, `sid`, `expires`, `expiry`, `policy` |
|
|
188
|
+
|
|
189
|
+
The `x-amz-` / `x-goog-` prefix rules subsume the explicit AWS / GCP rows; both are listed for
|
|
190
|
+
clarity. `Expires` / `se` / `X-Amz-Expires` / `X-Goog-Expires` are stripped because a signed-URL
|
|
191
|
+
expiry timestamp is a replay / privacy signal; a plain content `?t=42` seek timestamp is a
|
|
192
|
+
different name and survives. The list is opt-in (`maskAssetUrls`) and auditable here; a host that
|
|
193
|
+
needs different membership uses `maskAssetUrlFn` for full control.
|
|
194
|
+
|
|
195
|
+
**Known residuals of the built-in `maskAssetUrls` strip.** The boolean strip is keyed on
|
|
196
|
+
`URLSearchParams` param **names**, which split a query only on `&`. Two shapes therefore fall
|
|
197
|
+
outside it:
|
|
198
|
+
|
|
199
|
+
- **Matrix / `;`-separated query params.** A legacy `;`-delimited query
|
|
200
|
+
(`?w=10;token=SECRET&sig=x`) hides the token inside another param's *value* (`w` =
|
|
201
|
+
`"10;token=SECRET"`), so the name match never sees it and it survives on the wire (the
|
|
202
|
+
separately-named `sig` is still stripped). Semicolon query separators are legacy and uncommon,
|
|
203
|
+
so the built-in strip does not split on `;`; a host whose signed URLs use matrix params (or that
|
|
204
|
+
needs airtight redaction) should use `maskAssetUrlFn`, which receives the raw URL string and can
|
|
205
|
+
redact any shape.
|
|
206
|
+
- **URL fragments.** A token in the fragment (`#access_token=...`) is not part of the query at
|
|
207
|
+
all. When the fragment carries a **denylisted param name** the built-in strip now drops the
|
|
208
|
+
whole fragment (it is never needed for an asset/media fetch); a fragment that merely contains
|
|
209
|
+
`=` without a denied name (an opaque app-router route, for example) is left intact, so a host
|
|
210
|
+
with credential-bearing fragments under non-denylisted names should still reach for
|
|
211
|
+
`maskAssetUrlFn`.
|
|
212
|
+
|
|
213
|
+
Both residuals are fully covered by `maskAssetUrlFn`, which sees the complete URL string before
|
|
214
|
+
any name-keyed parsing.
|
|
215
|
+
|
|
124
216
|
## 5. Host must-nevers
|
|
125
217
|
|
|
126
218
|
Hosts embedding PhantomStream must preserve these rules:
|
|
@@ -132,8 +224,147 @@ Hosts embedding PhantomStream must preserve these rules:
|
|
|
132
224
|
`textContent`; custom renderers should do the same.
|
|
133
225
|
- Never add an opt-out switch for the capture or render sanitizers.
|
|
134
226
|
- Never weaken the adopted CSP policy below script-blocking.
|
|
227
|
+
- Never relax the fail-closed asset-origin policy into an allow-by-default posture, and
|
|
228
|
+
never move the asset fetch gate after the URL is written into the mirror (a post-write
|
|
229
|
+
gate is too late -- the browser has already issued the GET). Widen reachable origins
|
|
230
|
+
only through `allowAssetOrigins` / the `assetOriginPolicy` hook.
|
|
231
|
+
|
|
232
|
+
## 6. Viewer-side resource fetching
|
|
233
|
+
|
|
234
|
+
v2.0 changes the viewer's verb from **render-inert to fetch**. In v1 the mirror only rendered
|
|
235
|
+
attacker-influenced markup inertly; from Phase 12 on, a mirrored `<img>` / `<source>` / `<video>`
|
|
236
|
+
poster / CSS `background-image` causes the **viewer's own browser** to issue a GET from the
|
|
237
|
+
viewer's (possibly privileged) network. Static images are the first instance of this fetch
|
|
238
|
+
surface, so the viewer-fetch security model lands here. Mirrored asset bytes never traverse the
|
|
239
|
+
relay -- the wire carries URL strings only; the viewer fetches directly from the source/CDN.
|
|
240
|
+
|
|
241
|
+
**Fail-closed origin policy (MSEC-01).** A pure, fail-closed origin classifier
|
|
242
|
+
(`classifyAssetOrigin` in `src/renderer/asset-policy.js`) decides which asset URLs the viewer may
|
|
243
|
+
fetch. It is a *fetch* control, distinct from the *injection* control `hasDangerousScheme`: an
|
|
244
|
+
`https://` URL to an internal host passes the injection check yet is a blind-SSRF / tracking
|
|
245
|
+
surface, which this classifier blocks. The default posture is **https-only plus a private /
|
|
246
|
+
internal denylist**; anything not provably public-https is blocked:
|
|
247
|
+
|
|
248
|
+
- scheme must be `https:` (non-`http(s)` and plain `http:` are blocked);
|
|
249
|
+
- hosts denied: `localhost`, `127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`,
|
|
250
|
+
`192.168.0.0/16`, `169.254.0.0/16` (link-local), `::1`, `fc00::/7` (`fc..`/`fd..` ULA), and
|
|
251
|
+
`.local` / unqualified (dotless) hosts;
|
|
252
|
+
- any parse error fails closed (blocked).
|
|
253
|
+
|
|
254
|
+
A blocked origin is replaced by a dimensioned `data-ps-asset-unavailable="blocked-origin"`
|
|
255
|
+
placeholder, so the viewer's browser **never issues the GET** -- no tracking beacon fires and no
|
|
256
|
+
internal host is probed.
|
|
257
|
+
|
|
258
|
+
**Host override surface.** Two seams widen the conservative default, never relax it below
|
|
259
|
+
fail-closed:
|
|
260
|
+
|
|
261
|
+
- `assetOriginPolicy(url, ctx) => boolean` -- a host hook that **fails closed**: it blocks on a
|
|
262
|
+
thrown error or any non-`true` return (it can never open a URL the classifier would allow only
|
|
263
|
+
by throwing). This mirrors the capture-side `compileMaskSelector` fail-closed-and-loud
|
|
264
|
+
precedent.
|
|
265
|
+
- `allowAssetOrigins` -- a convenience host allowlist; a listed host passes the gate even if the
|
|
266
|
+
classifier would otherwise deny it.
|
|
267
|
+
|
|
268
|
+
**`mediaMode` switch (MSEC-02).** A `createViewer` config option selects the privacy / bandwidth
|
|
269
|
+
posture: `off` (no viewer asset fetch at all -- every asset becomes a placeholder), `poster`
|
|
270
|
+
(*target* posture: posters/placeholders only, full-asset fetch withheld -- see the Phase-12
|
|
271
|
+
interim note below), and `reference` (full by-reference fetch). The **default is `reference`** --
|
|
272
|
+
media-by-reference is on by default (the milestone's purpose) and the fail-closed origin policy is
|
|
273
|
+
the safety net. An invalid `mediaMode` throws at viewer-factory time (the sanctioned throw site).
|
|
274
|
+
|
|
275
|
+
> **Phase 12 interim semantics for `poster` (review WR-02 -- read before relying on `poster`).**
|
|
276
|
+
> The poster / full-asset split is a Phase 13 deliverable, gated on the `<video>` / `<audio>`
|
|
277
|
+
> element actually shipping. In Phase 12 `poster` therefore behaves **identically to `reference`
|
|
278
|
+
> for images**: every origin-permitted image (content image OR `<video>` poster) is allowed to
|
|
279
|
+
> fetch, gated only by the fail-closed origin policy -- there is no content-image-vs-poster
|
|
280
|
+
> distinction yet (the gate's `kind` parameter is threaded through but does not yet narrow
|
|
281
|
+
> `poster`). A host that needs *all* content-image fetches suppressed today must use `off`, not
|
|
282
|
+
> `poster`. The stricter "posters only, full-asset withheld" guarantee lands in Phase 13.
|
|
283
|
+
|
|
284
|
+
**Pre-write timing (the non-negotiable rule).** The gate runs **before** the asset URL is written
|
|
285
|
+
into the mirror DOM, so a blocked origin never reaches a fetch. For diffs this is pre-`setAttribute`
|
|
286
|
+
(ATTR) and pre-`importNode` (ADD / subtree, over inert template content). For the **snapshot** it
|
|
287
|
+
is gated at the **string / payload layer**, before the srcdoc is assembled (`gateSnapshotAssets`
|
|
288
|
+
in `src/renderer/snapshot.js`): a real browser's HTML parser begins fetching `<img src>` *during*
|
|
289
|
+
srcdoc parse, before the post-parse scrub can run, so a post-parse-only gate would let the initial
|
|
290
|
+
snapshot image GET fire for a blocked origin. This string-layer rewrite operates on the typed
|
|
291
|
+
asset values being emitted -- it is **not** the scrub-then-reparse mutation-XSS anti-pattern
|
|
292
|
+
(`payload.html` stays raw for everything else); the post-parse DOM gate remains as
|
|
293
|
+
defense-in-depth.
|
|
294
|
+
|
|
295
|
+
**Variant pinning (ASST-03).** When a mirrored element carries the clone-only `data-ps-currentsrc`
|
|
296
|
+
enrichment, the renderer sets the element's effective `src` to that value and neutralizes
|
|
297
|
+
`srcset` / `sizes`, so the cross-origin viewer (different DPR/viewport) loads the same asset the
|
|
298
|
+
origin displayed rather than re-negotiating a different variant.
|
|
299
|
+
|
|
300
|
+
**Unchanged sandbox / CSP (no widening).** Phase 12 adds **no** sandbox or CSP-script change. The
|
|
301
|
+
iframe sandbox remains exactly `allow-same-origin` (never `allow-scripts`; the asset code contains
|
|
302
|
+
no `allow-scripts` literal and the static scan stays green), and the srcdoc CSP is unchanged:
|
|
303
|
+
`default-src 'none'`, the existing `img-src http: https: data:` already covers every static image
|
|
304
|
+
surface (including `<video>` poster), there is **no `script-src`**, and there is **no `media-src`**
|
|
305
|
+
-- the scoped `media-src` directive is deferred to Phase 13 (when `<video>`/`<audio>` actually
|
|
306
|
+
needs it). Capture-side asset/media URL **masking** and `referrerpolicy` completion are **done in
|
|
307
|
+
Phase 15** (MSEC-03/MSEC-04): see §4 Masking Guarantees for the masking vocabulary and the
|
|
308
|
+
**Referrer and credentials** subsection below for the `referrerpolicy="no-referrer"` /
|
|
309
|
+
no-credentials posture. Phase 12 makes the fetch-gate decisions, not the masking.
|
|
310
|
+
|
|
311
|
+
**Referrer and credentials (MSEC-04, completed in Phase 15).** Because the viewer's browser now
|
|
312
|
+
fetches mirrored asset/media URLs, two leakage vectors are closed at the document level:
|
|
313
|
+
|
|
314
|
+
- **`referrerpolicy="no-referrer"`** is delivered once as a document-level
|
|
315
|
+
`<meta name="referrer" content="no-referrer">` injected into the srcdoc `<head>` **immediately
|
|
316
|
+
after the CSP meta** (`src/renderer/snapshot.js`), before the charset, viewport, the first
|
|
317
|
+
stylesheet `<link>`, and the first payload `<img>`. One document control covers **every**
|
|
318
|
+
viewer subresource fetch -- `<img>`, `<video>` / `<source>`, `<video>` poster, CSS
|
|
319
|
+
`background-image` / `url()`, fonts -- including CSS-initiated fetches that a per-element
|
|
320
|
+
`referrerpolicy` attribute could never reach. The mirrored page URL (which can itself carry
|
|
321
|
+
tokens) therefore never leaks in the `Referer` header to third-party CDNs.
|
|
322
|
+
- **No credentials by default.** The posture already holds and is now documented and asserted: an
|
|
323
|
+
`allow-same-origin`-sandboxed srcdoc with **no `crossorigin` attribute** anywhere issues no-CORS
|
|
324
|
+
cross-origin GETs that omit credentials to third-party origins. Phase 15 deliberately adds **no**
|
|
325
|
+
`crossorigin` attribute -- forcing `crossorigin="anonymous"` would turn benign fetches into CORS
|
|
326
|
+
requests and break otherwise-fine assets served without `Access-Control-Allow-Origin`.
|
|
327
|
+
|
|
328
|
+
The string-layer contract (the `no-referrer` meta is present, ordered after the CSP meta and
|
|
329
|
+
before the first subresource, and no `crossorigin` attribute is emitted) is unit-pinned. The
|
|
330
|
+
**live** referrer suppression and credential omission -- real `Referer`-less GETs and CSP
|
|
331
|
+
enforcement observed in a browser -- are the documented deferred real-browser UAT, since jsdom
|
|
332
|
+
neither parses the srcdoc nor issues real subresource requests (the same hidden-tab / jsdom limit
|
|
333
|
+
as Phases 13-14).
|
|
334
|
+
|
|
335
|
+
### Parent-Realm Object-URL Threat Model
|
|
336
|
+
|
|
337
|
+
Adaptive playback (HLS / DASH via Media Source Extensions) mints a `blob:` **object URL** in the
|
|
338
|
+
**parent (renderer-owning) realm** -- `URL.createObjectURL(mediaSource)` -- and assigns it to the
|
|
339
|
+
**inert in-iframe** `<video>.src`. hls.js runs in the parent and `attachMedia`s the iframe element;
|
|
340
|
+
the **parent** fetches every media segment and appends to the `SourceBuffer`. This is the one
|
|
341
|
+
genuinely novel cross-realm construct in v2.0, so its blast radius is threat-modeled here against
|
|
342
|
+
the existing sandbox. The asset under consideration is that parent-origin `blob:` object URL.
|
|
343
|
+
|
|
344
|
+
| # | Threat | STRIDE | Why it is mitigated |
|
|
345
|
+
|---|---|---|---|
|
|
346
|
+
| 1 | Mirrored (attacker-influenced) content scripts the page to read the object URL's bytes and exfiltrate them | Information Disclosure | The iframe sandbox is **exactly `allow-same-origin`, never `allow-scripts`** -- no script runs inside the mirror at all. A `blob:` URL is readable only via `fetch` / `XHR` / `FileReader`, all of which require script. With no script the child can *play* the element but cannot *read* the blob. `createViewer` reads the token back and throws `viewer-sandbox-invalid` on any deviation. |
|
|
347
|
+
| 2 | The object URL is parent-origin -- can the child reach parent-origin `blob:` resources for non-media use? | Information Disclosure / Elevation of Privilege | The blob's origin is the **parent document's**, not the mirrored page's. The child has no script to dereference it, and CSP `media-src blob:` permits only media *loading* of `blob:`, not `fetch` / `connect` (there is **no `connect-src`**). The blob is usable solely as a media source by the inert element. |
|
|
348
|
+
| 3 | A leaked / long-lived object URL persists after the player is gone (use-after-free / leak / cross-session bleed) | Information Disclosure / Denial of Service | The object URL is **revoked on `destroy` / `destroyAll`** (`URL.revokeObjectURL`), and `destroyAll()` runs before any new-identity snapshot document swap, tearing down every parent-realm player first. A revoked `blob:` is dead; a later session cannot resolve it. |
|
|
349
|
+
| 4 | `blob:` widens the CSP enough to load arbitrary local resources | Tampering | `blob:` is scoped to **`media-src` only** (not `img-src`, not `default-src`). `default-src 'none'` plus the absence of `script-src` / `connect-src` means `blob:` cannot be used for script, XHR, or any non-media fetch. |
|
|
350
|
+
| 5 | The parent realm itself is the privileged attacker target (segment fetches, MSE in the parent) | Elevation of Privilege | The parent realm is **renderer / host code**, not mirrored content -- it was never sandboxed and is trusted by construction. The threat boundary is *mirrored content -> host*, and that boundary **is** the sandbox; moving the player to the parent is precisely what *avoids* granting the sandbox `allow-scripts`. |
|
|
351
|
+
|
|
352
|
+
**Plain-language worst case:** the child iframe plays the parent's media object URL but cannot
|
|
353
|
+
script, read, copy, or exfiltrate it -- there is no `allow-scripts`, no `connect-src`, and the
|
|
354
|
+
`blob:` is dead the moment the player is destroyed. The only thing the mirror can do with the
|
|
355
|
+
object URL is what a `<video>` does with a source it was handed: render frames. An attacker who
|
|
356
|
+
fully controls the mirrored page gains the ability to display media the host already chose to
|
|
357
|
+
mirror, and nothing more.
|
|
358
|
+
|
|
359
|
+
Backing tests: the sandbox token is unchanged (`createViewer` `viewer-sandbox-invalid` + the
|
|
360
|
+
purity scan); `allow-scripts` is absent from `src/renderer/media-player.js` (the purity-test
|
|
361
|
+
renderer glob covers it, and `tests/security-media.test.js` names the case); `blob:` is scoped to
|
|
362
|
+
`media-src` with no `script-src` / `connect-src` (`tests/renderer-media-csp.test.js`); the object
|
|
363
|
+
URL is revoked on `destroy` / `destroyAll` (`tests/renderer-media-player.test.js` and
|
|
364
|
+
`tests/security-media.test.js`); and a late cross-session `STREAM.MEDIA` frame is rejected by
|
|
365
|
+
`isCurrentStream` (`tests/security-media.test.js`, citing `tests/renderer-media.test.js`).
|
|
135
366
|
|
|
136
|
-
##
|
|
367
|
+
## 7. Residual Risks
|
|
137
368
|
|
|
138
369
|
Snapshot `payload.html` remains string-raw at the srcdoc assembly layer by design. Scrubbing an
|
|
139
370
|
HTML string and then asking the browser to parse it again is the mutation-XSS failure mode. The
|
|
@@ -37,11 +37,20 @@ var viewer = createViewer({
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
function sumCounts(map) {
|
|
41
|
+
var total = 0;
|
|
42
|
+
map = map || {};
|
|
43
|
+
Object.keys(map).forEach(function (key) {
|
|
44
|
+
total += map[key] || 0;
|
|
45
|
+
});
|
|
46
|
+
return total;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
viewer.on('state', function (event) {
|
|
50
|
+
document.getElementById('lifecycle').textContent = event.state;
|
|
42
51
|
});
|
|
43
52
|
viewer.on('health', function (health) {
|
|
44
|
-
document.getElementById('health').textContent = String(health.
|
|
53
|
+
document.getElementById('health').textContent = String(sumCounts(health.receivedByType)) + ' frames';
|
|
45
54
|
});
|
|
46
55
|
</script>
|
|
47
56
|
</body>
|
|
@@ -37,11 +37,18 @@ var viewer = createViewer({
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
function sumCounts(map) {
|
|
41
|
+
var total = 0;
|
|
42
|
+
map = map || {};
|
|
43
|
+
Object.keys(map).forEach(function (key) { total += map[key] || 0; });
|
|
44
|
+
return total;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
viewer.on('state', function (event) {
|
|
48
|
+
document.getElementById('lifecycle').textContent = event.state;
|
|
42
49
|
});
|
|
43
50
|
viewer.on('health', function (health) {
|
|
44
|
-
document.getElementById('health').textContent = String(health.
|
|
51
|
+
document.getElementById('health').textContent = String(sumCounts(health.receivedByType)) + ' frames';
|
|
45
52
|
});
|
|
46
53
|
</script>
|
|
47
54
|
</body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@full-self-browsing/phantom-stream",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "DOM-native live browser mirroring: snapshot + MutationObserver diff streaming with stable node identity, compressed transport, and bidirectional remote control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -101,6 +101,14 @@
|
|
|
101
101
|
"publint": "^0.3.21",
|
|
102
102
|
"typescript": "^6.0.3"
|
|
103
103
|
},
|
|
104
|
+
"peerDependencies": {
|
|
105
|
+
"hls.js": ">=1.5.0"
|
|
106
|
+
},
|
|
107
|
+
"peerDependenciesMeta": {
|
|
108
|
+
"hls.js": {
|
|
109
|
+
"optional": true
|
|
110
|
+
}
|
|
111
|
+
},
|
|
104
112
|
"dependencies": {
|
|
105
113
|
"ws": "8.21.0"
|
|
106
114
|
}
|