shellpuppet 0.0.1 → 0.2.0
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/LICENSE +202 -0
- package/NOTICE +31 -0
- package/README.md +499 -8
- package/dist/cli/desktopShortcut.d.ts +22 -0
- package/dist/cli/desktopShortcut.js +157 -0
- package/dist/cli/desktopShortcut.js.map +1 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.js +846 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/http.d.ts +143 -0
- package/dist/client/http.js +581 -0
- package/dist/client/http.js.map +1 -0
- package/dist/core/dialogs.d.ts +96 -0
- package/dist/core/dialogs.js +226 -0
- package/dist/core/dialogs.js.map +1 -0
- package/dist/core/echo.d.ts +71 -0
- package/dist/core/echo.js +249 -0
- package/dist/core/echo.js.map +1 -0
- package/dist/core/find.d.ts +34 -0
- package/dist/core/find.js +41 -0
- package/dist/core/find.js.map +1 -0
- package/dist/core/keys.d.ts +22 -0
- package/dist/core/keys.js +80 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/manager.d.ts +96 -0
- package/dist/core/manager.js +271 -0
- package/dist/core/manager.js.map +1 -0
- package/dist/core/nativePty.d.ts +73 -0
- package/dist/core/nativePty.js +161 -0
- package/dist/core/nativePty.js.map +1 -0
- package/dist/core/policy.d.ts +61 -0
- package/dist/core/policy.js +143 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/promptDetector.d.ts +109 -0
- package/dist/core/promptDetector.js +897 -0
- package/dist/core/promptDetector.js.map +1 -0
- package/dist/core/reasoning.d.ts +265 -0
- package/dist/core/reasoning.js +933 -0
- package/dist/core/reasoning.js.map +1 -0
- package/dist/core/regexBudget.d.ts +64 -0
- package/dist/core/regexBudget.js +103 -0
- package/dist/core/regexBudget.js.map +1 -0
- package/dist/core/renderer.d.ts +127 -0
- package/dist/core/renderer.js +316 -0
- package/dist/core/renderer.js.map +1 -0
- package/dist/core/selection.d.ts +6 -0
- package/dist/core/selection.js +48 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/session.d.ts +565 -0
- package/dist/core/session.js +1450 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/types.d.ts +316 -0
- package/dist/core/types.js +71 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/waiter.d.ts +94 -0
- package/dist/core/waiter.js +310 -0
- package/dist/core/waiter.js.map +1 -0
- package/dist/core/windowsConsoleHost.d.ts +147 -0
- package/dist/core/windowsConsoleHost.js +588 -0
- package/dist/core/windowsConsoleHost.js.map +1 -0
- package/dist/core/windowsPtyStart.d.ts +161 -0
- package/dist/core/windowsPtyStart.js +236 -0
- package/dist/core/windowsPtyStart.js.map +1 -0
- package/dist/daemon/audit.d.ts +23 -0
- package/dist/daemon/audit.js +51 -0
- package/dist/daemon/audit.js.map +1 -0
- package/dist/daemon/auth.d.ts +197 -0
- package/dist/daemon/auth.js +366 -0
- package/dist/daemon/auth.js.map +1 -0
- package/dist/daemon/config.d.ts +119 -0
- package/dist/daemon/config.js +568 -0
- package/dist/daemon/config.js.map +1 -0
- package/dist/daemon/folderPicker.d.ts +27 -0
- package/dist/daemon/folderPicker.js +115 -0
- package/dist/daemon/folderPicker.js.map +1 -0
- package/dist/daemon/index.d.ts +7 -0
- package/dist/daemon/index.js +88 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/daemon/launchProfiles.d.ts +155 -0
- package/dist/daemon/launchProfiles.js +554 -0
- package/dist/daemon/launchProfiles.js.map +1 -0
- package/dist/daemon/liveness.d.ts +36 -0
- package/dist/daemon/liveness.js +71 -0
- package/dist/daemon/liveness.js.map +1 -0
- package/dist/daemon/logger.d.ts +7 -0
- package/dist/daemon/logger.js +29 -0
- package/dist/daemon/logger.js.map +1 -0
- package/dist/daemon/meta.d.ts +9 -0
- package/dist/daemon/meta.js +24 -0
- package/dist/daemon/meta.js.map +1 -0
- package/dist/daemon/paths.d.ts +85 -0
- package/dist/daemon/paths.js +154 -0
- package/dist/daemon/paths.js.map +1 -0
- package/dist/daemon/screenshot.d.ts +144 -0
- package/dist/daemon/screenshot.js +402 -0
- package/dist/daemon/screenshot.js.map +1 -0
- package/dist/daemon/server.d.ts +453 -0
- package/dist/daemon/server.js +3954 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/sessionFeed.d.ts +48 -0
- package/dist/daemon/sessionFeed.js +101 -0
- package/dist/daemon/sessionFeed.js.map +1 -0
- package/dist/daemon/terminalReports.d.ts +38 -0
- package/dist/daemon/terminalReports.js +84 -0
- package/dist/daemon/terminalReports.js.map +1 -0
- package/dist/daemon/viewerLauncher.d.ts +226 -0
- package/dist/daemon/viewerLauncher.js +562 -0
- package/dist/daemon/viewerLauncher.js.map +1 -0
- package/dist/daemon/viewerSync.d.ts +38 -0
- package/dist/daemon/viewerSync.js +83 -0
- package/dist/daemon/viewerSync.js.map +1 -0
- package/dist/mcp/config.d.ts +50 -0
- package/dist/mcp/config.js +95 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.js +78 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tools.d.ts +66 -0
- package/dist/mcp/tools.js +638 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/viewer/dashboard-folders.js +20 -0
- package/dist/viewer/dashboard-layout.js +52 -0
- package/dist/viewer/dashboard.css +67 -0
- package/dist/viewer/dashboard.html +44 -0
- package/dist/viewer/dashboard.js +1518 -0
- package/dist/viewer/icon-16.png +0 -0
- package/dist/viewer/icon-180.png +0 -0
- package/dist/viewer/icon-32.png +0 -0
- package/dist/viewer/icon-512.png +0 -0
- package/dist/viewer/icon.ico +0 -0
- package/dist/viewer/icon.svg +66 -0
- package/dist/viewer/index.html +61 -0
- package/dist/viewer/pane.js +736 -0
- package/dist/viewer/viewer.css +95 -0
- package/dist/viewer/viewer.js +84 -0
- package/package.json +66 -7
- package/index.js +0 -4
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token generation and verification (design §4.1).
|
|
3
|
+
*
|
|
4
|
+
* Five credentials, deliberately different in kind:
|
|
5
|
+
*
|
|
6
|
+
* - **Client token**: full API access; generated per daemon run, written to
|
|
7
|
+
* `daemon.json`, read by same-user clients. Rotates on restart. Travels in an
|
|
8
|
+
* `Authorization` header over HTTP, and on the query string for the two
|
|
9
|
+
* WebSocket routes, because a browser will not let a page set headers on an
|
|
10
|
+
* upgrade (design §4.1). It never appears in a URL a human is given.
|
|
11
|
+
* - **Viewer grant**: the `vt` in a viewer URL. **One use, short life.** It
|
|
12
|
+
* is not a session credential and cannot open a stream; it can only be
|
|
13
|
+
* exchanged, once, for the credential below. A viewer URL inevitably lands
|
|
14
|
+
* in the driving agent's transcript, in logs and in whatever the human
|
|
15
|
+
* pasted it into, so the thing that lands there has to become worthless
|
|
16
|
+
* the moment it has done its job: spent by the first redemption, or expired
|
|
17
|
+
* unopened. Until then it is a live bearer capability.
|
|
18
|
+
* - **Stream credential**: what a grant is exchanged for, delivered as an
|
|
19
|
+
* `HttpOnly` cookie scoped to that one session's path. The browser attaches
|
|
20
|
+
* it to the WebSocket upgrade on its own, so page scripts never hold it and
|
|
21
|
+
* cannot leak it. It lives as long as the session, because a viewer that
|
|
22
|
+
* reconnects after a dropped socket must not need a fresh URL.
|
|
23
|
+
*
|
|
24
|
+
* Read-only is a property of the grant, and so of the credential it
|
|
25
|
+
* becomes: it is enforced by the daemon, not by the viewer page. The page's
|
|
26
|
+
* own toggle stops that tab sending keystrokes and is a convenience; a
|
|
27
|
+
* read-only credential means the daemon will not accept them.
|
|
28
|
+
* - **Dashboard grant**: the `dt` in a dashboard URL. One use, short life,
|
|
29
|
+
* not a session credential, and it cannot open a stream. Its only use is
|
|
30
|
+
* to be exchanged, once, at `GET /dashboard` for the cookie below. The
|
|
31
|
+
* daemon mints it and never returns it to the caller.
|
|
32
|
+
* - **Dashboard credential**: what that grant becomes. One `HttpOnly` cookie
|
|
33
|
+
* for the whole dashboard, plus a ring of the eight newest per-document
|
|
34
|
+
* proofs. A second redemption replaces the credential and drops its proofs.
|
|
35
|
+
* The cookie opens a session stream when the upgrade carries a live proof
|
|
36
|
+
* as the `sp-csrf` subprotocol. A viewer cookie is not this credential.
|
|
37
|
+
*/
|
|
38
|
+
export type AuthResult = {
|
|
39
|
+
kind: 'client';
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'viewer';
|
|
42
|
+
sessionId: string;
|
|
43
|
+
readOnly: boolean;
|
|
44
|
+
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* How long an unredeemed viewer grant stays usable.
|
|
47
|
+
*
|
|
48
|
+
* The window we open ourselves redeems it in a second or two, so this bounds
|
|
49
|
+
* only the case where nobody opened the link: a URL sitting in a transcript,
|
|
50
|
+
* a chat message or a terminal scrollback. Five minutes is long enough to
|
|
51
|
+
* paste a link to a second device by hand and short enough that yesterday's
|
|
52
|
+
* transcript is inert. Expired is not a dead end: mint another.
|
|
53
|
+
*/
|
|
54
|
+
export declare const VIEWER_GRANT_TTL_MS: number;
|
|
55
|
+
/** How many per-document proofs the current dashboard credential keeps. */
|
|
56
|
+
export declare const DASHBOARD_PROOF_RING = 8;
|
|
57
|
+
export interface RedeemedGrant {
|
|
58
|
+
/** The value to put in the viewer's cookie. */
|
|
59
|
+
streamToken: string;
|
|
60
|
+
sessionId: string;
|
|
61
|
+
readOnly: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare function generateToken(): string;
|
|
64
|
+
/** Constant-time comparison over sha256 digests, so length never leaks. */
|
|
65
|
+
export declare function tokensEqual(a: string, b: string): boolean;
|
|
66
|
+
export declare class TokenStore {
|
|
67
|
+
private readonly clientToken;
|
|
68
|
+
private readonly grants;
|
|
69
|
+
private readonly streams;
|
|
70
|
+
private readonly dashboardGrants;
|
|
71
|
+
/** The one live dashboard credential. A new redemption replaces it. */
|
|
72
|
+
private dashboardCredential;
|
|
73
|
+
constructor(clientToken?: string);
|
|
74
|
+
get token(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Mint a one-use viewer grant for a session. `readOnly` rides with it, so a
|
|
77
|
+
* watch-only link cannot be turned into a typing one by the page that holds
|
|
78
|
+
* it.
|
|
79
|
+
*/
|
|
80
|
+
mintViewerGrant(sessionId: string, options?: {
|
|
81
|
+
readOnly?: boolean;
|
|
82
|
+
ttlMs?: number;
|
|
83
|
+
now?: number;
|
|
84
|
+
}): string;
|
|
85
|
+
/**
|
|
86
|
+
* Exchange a grant for a stream credential, consuming the grant. Returns
|
|
87
|
+
* null for an unknown, already-redeemed or expired grant. The three cases
|
|
88
|
+
* are deliberately indistinguishable to the caller.
|
|
89
|
+
*/
|
|
90
|
+
redeemViewerGrant(presented: string | undefined | null, now?: number): RedeemedGrant | null;
|
|
91
|
+
/** Verify a stream credential (the viewer's cookie). */
|
|
92
|
+
verifyStreamToken(presented: string | undefined | null): AuthResult;
|
|
93
|
+
/**
|
|
94
|
+
* Take back a grant and whatever it became: the grant itself if nobody spent
|
|
95
|
+
* it, and the stream credential it was exchanged for if somebody did.
|
|
96
|
+
*
|
|
97
|
+
* For a link minted on behalf of something with an end, which is the
|
|
98
|
+
* screenshot's headless browser and not a human's window. Its credential
|
|
99
|
+
* would otherwise live as long as the session, so a session photographed a
|
|
100
|
+
* thousand times would hold a thousand of them, each able to open a socket.
|
|
101
|
+
* A human's viewer is the opposite case and keeps its credential: a dropped
|
|
102
|
+
* socket must reconnect without a fresh link.
|
|
103
|
+
*/
|
|
104
|
+
revokeViewerGrant(grant: string): void;
|
|
105
|
+
/** Drop every viewer grant and credential scoped to a session (on kill/exit cleanup). */
|
|
106
|
+
revokeViewerTokens(sessionId: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Mint a one-use dashboard grant. It is not a session credential. The HTTP
|
|
109
|
+
* client cannot choose its lifetime: only a test passes `ttlMs`.
|
|
110
|
+
*/
|
|
111
|
+
mintDashboardGrant(options?: {
|
|
112
|
+
ttlMs?: number;
|
|
113
|
+
now?: number;
|
|
114
|
+
}): string;
|
|
115
|
+
/**
|
|
116
|
+
* Exchange a dashboard grant for the one dashboard credential, consuming
|
|
117
|
+
* the grant. Returns null for an unknown, already-redeemed or expired
|
|
118
|
+
* grant. The three cases are deliberately indistinguishable. A successful
|
|
119
|
+
* redemption replaces whatever credential was current and drops its proofs.
|
|
120
|
+
* A failed redemption leaves the current credential alone.
|
|
121
|
+
*/
|
|
122
|
+
redeemDashboardGrant(presented: string | undefined | null, now?: number): {
|
|
123
|
+
token: string;
|
|
124
|
+
} | null;
|
|
125
|
+
/** The dashboard cookie value, or false when nothing current matches. */
|
|
126
|
+
verifyDashboardToken(presented: string | undefined | null): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Take back a dashboard grant and the credential it became. An unspent
|
|
129
|
+
* grant is deleted. A spent one drops the credential and its proofs.
|
|
130
|
+
*/
|
|
131
|
+
revokeDashboardGrant(grant: string): void;
|
|
132
|
+
/**
|
|
133
|
+
* A fresh proof for the current credential, or null when there is none.
|
|
134
|
+
* The ninth proof drops the oldest.
|
|
135
|
+
*/
|
|
136
|
+
issueDashboardProof(): string | null;
|
|
137
|
+
/**
|
|
138
|
+
* Whether `presented` is one of the proofs still in the ring. The compare
|
|
139
|
+
* hashes both strings, so a wrong proof of the same length takes the same
|
|
140
|
+
* path as a right one.
|
|
141
|
+
*/
|
|
142
|
+
acceptsDashboardProof(presented: string | undefined | null): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Verify a bearer token. Only the client token authenticates this way:
|
|
145
|
+
* viewer credentials are cookie-borne and session-scoped, and are checked
|
|
146
|
+
* with `verifyStreamToken`. The dashboard cookie is checked with
|
|
147
|
+
* `verifyDashboardToken`.
|
|
148
|
+
*/
|
|
149
|
+
verify(presented: string | undefined | null): AuthResult;
|
|
150
|
+
private pruneExpired;
|
|
151
|
+
private pruneExpiredDashboard;
|
|
152
|
+
}
|
|
153
|
+
/** Extract a bearer token from an Authorization header value. */
|
|
154
|
+
export declare function bearerToken(header: string | undefined): string | null;
|
|
155
|
+
/**
|
|
156
|
+
* The viewer's cookie name. One name, but each is written with the session's
|
|
157
|
+
* own `Path`, so a browser watching several sessions keeps their credentials
|
|
158
|
+
* apart and sends only the one whose path matches the socket being opened.
|
|
159
|
+
*/
|
|
160
|
+
export declare const VIEWER_COOKIE = "sp_viewer";
|
|
161
|
+
/**
|
|
162
|
+
* Every value carried under `name` in a Cookie header, in order, with its
|
|
163
|
+
* percent-escapes decoded. More than one is possible: cookies ignore ports,
|
|
164
|
+
* so anything served from 127.0.0.1 can set a same-named cookie beside the
|
|
165
|
+
* daemon's own, and the caller tries each rather than trusting the first. A
|
|
166
|
+
* value whose escapes do not decode is skipped rather than thrown on.
|
|
167
|
+
*/
|
|
168
|
+
export declare function cookieValues(header: string | undefined, name: string): string[];
|
|
169
|
+
/** The first value carried under `name`, or null. */
|
|
170
|
+
export declare function cookieValue(header: string | undefined, name: string): string | null;
|
|
171
|
+
/**
|
|
172
|
+
* The `Set-Cookie` value delivering a stream credential.
|
|
173
|
+
*
|
|
174
|
+
* `HttpOnly` keeps it out of reach of page scripts, `SameSite=Strict` stops
|
|
175
|
+
* any other site's navigation carrying it and the per-session `Path` means a
|
|
176
|
+
* credential for one session is never even sent on another's socket. No
|
|
177
|
+
* `Max-Age`: it should die with the browsing session, not linger on disk.
|
|
178
|
+
* No `Secure`, deliberately: the daemon is loopback-only http, and a
|
|
179
|
+
* `Secure` cookie would simply never be stored.
|
|
180
|
+
*/
|
|
181
|
+
export declare function viewerCookie(sessionId: string, streamToken: string): string;
|
|
182
|
+
/**
|
|
183
|
+
* The dashboard's cookie name. One credential for the dashboard, so one
|
|
184
|
+
* path: `/`. Cookies ignore ports, and `cookieValues` tries every value.
|
|
185
|
+
*/
|
|
186
|
+
export declare const DASHBOARD_COOKIE = "sp_dash";
|
|
187
|
+
/**
|
|
188
|
+
* The `Set-Cookie` value delivering the dashboard credential.
|
|
189
|
+
*
|
|
190
|
+
* `HttpOnly` keeps it out of `document.cookie`. `SameSite=Strict` stops any
|
|
191
|
+
* other site's navigation carrying it. No `Max-Age`: it dies with the
|
|
192
|
+
* browsing session. No `Secure`: the daemon is loopback-only http, and a
|
|
193
|
+
* `Secure` cookie would never be stored. No `Domain`: it stays host-only.
|
|
194
|
+
*/
|
|
195
|
+
export declare function dashboardCookie(token: string): string;
|
|
196
|
+
/** The proof inside `sp-csrf.<64 hex>`, or null when the protocol is not that. */
|
|
197
|
+
export declare function dashboardProofFromProtocol(protocol: string): string | null;
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token generation and verification (design §4.1).
|
|
3
|
+
*
|
|
4
|
+
* Five credentials, deliberately different in kind:
|
|
5
|
+
*
|
|
6
|
+
* - **Client token**: full API access; generated per daemon run, written to
|
|
7
|
+
* `daemon.json`, read by same-user clients. Rotates on restart. Travels in an
|
|
8
|
+
* `Authorization` header over HTTP, and on the query string for the two
|
|
9
|
+
* WebSocket routes, because a browser will not let a page set headers on an
|
|
10
|
+
* upgrade (design §4.1). It never appears in a URL a human is given.
|
|
11
|
+
* - **Viewer grant**: the `vt` in a viewer URL. **One use, short life.** It
|
|
12
|
+
* is not a session credential and cannot open a stream; it can only be
|
|
13
|
+
* exchanged, once, for the credential below. A viewer URL inevitably lands
|
|
14
|
+
* in the driving agent's transcript, in logs and in whatever the human
|
|
15
|
+
* pasted it into, so the thing that lands there has to become worthless
|
|
16
|
+
* the moment it has done its job: spent by the first redemption, or expired
|
|
17
|
+
* unopened. Until then it is a live bearer capability.
|
|
18
|
+
* - **Stream credential**: what a grant is exchanged for, delivered as an
|
|
19
|
+
* `HttpOnly` cookie scoped to that one session's path. The browser attaches
|
|
20
|
+
* it to the WebSocket upgrade on its own, so page scripts never hold it and
|
|
21
|
+
* cannot leak it. It lives as long as the session, because a viewer that
|
|
22
|
+
* reconnects after a dropped socket must not need a fresh URL.
|
|
23
|
+
*
|
|
24
|
+
* Read-only is a property of the grant, and so of the credential it
|
|
25
|
+
* becomes: it is enforced by the daemon, not by the viewer page. The page's
|
|
26
|
+
* own toggle stops that tab sending keystrokes and is a convenience; a
|
|
27
|
+
* read-only credential means the daemon will not accept them.
|
|
28
|
+
* - **Dashboard grant**: the `dt` in a dashboard URL. One use, short life,
|
|
29
|
+
* not a session credential, and it cannot open a stream. Its only use is
|
|
30
|
+
* to be exchanged, once, at `GET /dashboard` for the cookie below. The
|
|
31
|
+
* daemon mints it and never returns it to the caller.
|
|
32
|
+
* - **Dashboard credential**: what that grant becomes. One `HttpOnly` cookie
|
|
33
|
+
* for the whole dashboard, plus a ring of the eight newest per-document
|
|
34
|
+
* proofs. A second redemption replaces the credential and drops its proofs.
|
|
35
|
+
* The cookie opens a session stream when the upgrade carries a live proof
|
|
36
|
+
* as the `sp-csrf` subprotocol. A viewer cookie is not this credential.
|
|
37
|
+
*/
|
|
38
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
39
|
+
/**
|
|
40
|
+
* How long an unredeemed viewer grant stays usable.
|
|
41
|
+
*
|
|
42
|
+
* The window we open ourselves redeems it in a second or two, so this bounds
|
|
43
|
+
* only the case where nobody opened the link: a URL sitting in a transcript,
|
|
44
|
+
* a chat message or a terminal scrollback. Five minutes is long enough to
|
|
45
|
+
* paste a link to a second device by hand and short enough that yesterday's
|
|
46
|
+
* transcript is inert. Expired is not a dead end: mint another.
|
|
47
|
+
*/
|
|
48
|
+
export const VIEWER_GRANT_TTL_MS = 5 * 60_000;
|
|
49
|
+
/** How many per-document proofs the current dashboard credential keeps. */
|
|
50
|
+
export const DASHBOARD_PROOF_RING = 8;
|
|
51
|
+
export function generateToken() {
|
|
52
|
+
return randomBytes(32).toString('hex');
|
|
53
|
+
}
|
|
54
|
+
/** Constant-time comparison over sha256 digests, so length never leaks. */
|
|
55
|
+
export function tokensEqual(a, b) {
|
|
56
|
+
const da = createHash('sha256').update(a).digest();
|
|
57
|
+
const db = createHash('sha256').update(b).digest();
|
|
58
|
+
return timingSafeEqual(da, db);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Find a key by constant-time comparison rather than by lookup. A `Map.get`
|
|
62
|
+
* would be faster and would compare the presented string against stored keys
|
|
63
|
+
* in whatever way the engine sees fit; these are secrets, so every comparison
|
|
64
|
+
* goes through `tokensEqual`.
|
|
65
|
+
*/
|
|
66
|
+
function findKey(store, presented) {
|
|
67
|
+
for (const key of store.keys()) {
|
|
68
|
+
if (tokensEqual(presented, key))
|
|
69
|
+
return key;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
export class TokenStore {
|
|
74
|
+
clientToken;
|
|
75
|
+
grants = new Map();
|
|
76
|
+
streams = new Map();
|
|
77
|
+
dashboardGrants = new Map();
|
|
78
|
+
/** The one live dashboard credential. A new redemption replaces it. */
|
|
79
|
+
dashboardCredential = null;
|
|
80
|
+
constructor(clientToken = generateToken()) {
|
|
81
|
+
this.clientToken = clientToken;
|
|
82
|
+
}
|
|
83
|
+
get token() {
|
|
84
|
+
return this.clientToken;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Mint a one-use viewer grant for a session. `readOnly` rides with it, so a
|
|
88
|
+
* watch-only link cannot be turned into a typing one by the page that holds
|
|
89
|
+
* it.
|
|
90
|
+
*/
|
|
91
|
+
mintViewerGrant(sessionId, options = {}) {
|
|
92
|
+
const now = options.now ?? Date.now();
|
|
93
|
+
this.pruneExpired(now);
|
|
94
|
+
const token = generateToken();
|
|
95
|
+
this.grants.set(token, {
|
|
96
|
+
sessionId,
|
|
97
|
+
readOnly: options.readOnly ?? false,
|
|
98
|
+
expiresAt: now + (options.ttlMs ?? VIEWER_GRANT_TTL_MS),
|
|
99
|
+
});
|
|
100
|
+
return token;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Exchange a grant for a stream credential, consuming the grant. Returns
|
|
104
|
+
* null for an unknown, already-redeemed or expired grant. The three cases
|
|
105
|
+
* are deliberately indistinguishable to the caller.
|
|
106
|
+
*/
|
|
107
|
+
redeemViewerGrant(presented, now = Date.now()) {
|
|
108
|
+
this.pruneExpired(now);
|
|
109
|
+
if (presented === undefined || presented === null || presented === '')
|
|
110
|
+
return null;
|
|
111
|
+
const key = findKey(this.grants, presented);
|
|
112
|
+
if (key === null)
|
|
113
|
+
return null;
|
|
114
|
+
const grant = this.grants.get(key);
|
|
115
|
+
if (grant === undefined)
|
|
116
|
+
return null;
|
|
117
|
+
// One use: gone whether or not the caller does anything with it.
|
|
118
|
+
this.grants.delete(key);
|
|
119
|
+
if (grant.expiresAt <= now)
|
|
120
|
+
return null;
|
|
121
|
+
const streamToken = generateToken();
|
|
122
|
+
this.streams.set(streamToken, {
|
|
123
|
+
sessionId: grant.sessionId,
|
|
124
|
+
readOnly: grant.readOnly,
|
|
125
|
+
grant: key,
|
|
126
|
+
});
|
|
127
|
+
return { streamToken, sessionId: grant.sessionId, readOnly: grant.readOnly };
|
|
128
|
+
}
|
|
129
|
+
/** Verify a stream credential (the viewer's cookie). */
|
|
130
|
+
verifyStreamToken(presented) {
|
|
131
|
+
if (presented === undefined || presented === null || presented === '')
|
|
132
|
+
return null;
|
|
133
|
+
const key = findKey(this.streams, presented);
|
|
134
|
+
if (key === null)
|
|
135
|
+
return null;
|
|
136
|
+
const credential = this.streams.get(key);
|
|
137
|
+
if (credential === undefined)
|
|
138
|
+
return null;
|
|
139
|
+
return {
|
|
140
|
+
kind: 'viewer',
|
|
141
|
+
sessionId: credential.sessionId,
|
|
142
|
+
readOnly: credential.readOnly,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Take back a grant and whatever it became: the grant itself if nobody spent
|
|
147
|
+
* it, and the stream credential it was exchanged for if somebody did.
|
|
148
|
+
*
|
|
149
|
+
* For a link minted on behalf of something with an end, which is the
|
|
150
|
+
* screenshot's headless browser and not a human's window. Its credential
|
|
151
|
+
* would otherwise live as long as the session, so a session photographed a
|
|
152
|
+
* thousand times would hold a thousand of them, each able to open a socket.
|
|
153
|
+
* A human's viewer is the opposite case and keeps its credential: a dropped
|
|
154
|
+
* socket must reconnect without a fresh link.
|
|
155
|
+
*/
|
|
156
|
+
revokeViewerGrant(grant) {
|
|
157
|
+
if (grant === '')
|
|
158
|
+
return;
|
|
159
|
+
const key = findKey(this.grants, grant);
|
|
160
|
+
if (key !== null)
|
|
161
|
+
this.grants.delete(key);
|
|
162
|
+
for (const [token, credential] of this.streams) {
|
|
163
|
+
if (tokensEqual(credential.grant, grant))
|
|
164
|
+
this.streams.delete(token);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Drop every viewer grant and credential scoped to a session (on kill/exit cleanup). */
|
|
168
|
+
revokeViewerTokens(sessionId) {
|
|
169
|
+
for (const [token, grant] of this.grants) {
|
|
170
|
+
if (grant.sessionId === sessionId)
|
|
171
|
+
this.grants.delete(token);
|
|
172
|
+
}
|
|
173
|
+
for (const [token, credential] of this.streams) {
|
|
174
|
+
if (credential.sessionId === sessionId)
|
|
175
|
+
this.streams.delete(token);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Mint a one-use dashboard grant. It is not a session credential. The HTTP
|
|
180
|
+
* client cannot choose its lifetime: only a test passes `ttlMs`.
|
|
181
|
+
*/
|
|
182
|
+
mintDashboardGrant(options = {}) {
|
|
183
|
+
const now = options.now ?? Date.now();
|
|
184
|
+
this.pruneExpiredDashboard(now);
|
|
185
|
+
const token = generateToken();
|
|
186
|
+
this.dashboardGrants.set(token, {
|
|
187
|
+
expiresAt: now + (options.ttlMs ?? VIEWER_GRANT_TTL_MS),
|
|
188
|
+
});
|
|
189
|
+
return token;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Exchange a dashboard grant for the one dashboard credential, consuming
|
|
193
|
+
* the grant. Returns null for an unknown, already-redeemed or expired
|
|
194
|
+
* grant. The three cases are deliberately indistinguishable. A successful
|
|
195
|
+
* redemption replaces whatever credential was current and drops its proofs.
|
|
196
|
+
* A failed redemption leaves the current credential alone.
|
|
197
|
+
*/
|
|
198
|
+
redeemDashboardGrant(presented, now = Date.now()) {
|
|
199
|
+
this.pruneExpiredDashboard(now);
|
|
200
|
+
if (presented === undefined || presented === null || presented === '')
|
|
201
|
+
return null;
|
|
202
|
+
const key = findKey(this.dashboardGrants, presented);
|
|
203
|
+
if (key === null)
|
|
204
|
+
return null;
|
|
205
|
+
const grant = this.dashboardGrants.get(key);
|
|
206
|
+
this.dashboardGrants.delete(key);
|
|
207
|
+
if (grant === undefined || grant.expiresAt <= now)
|
|
208
|
+
return null;
|
|
209
|
+
const token = generateToken();
|
|
210
|
+
this.dashboardCredential = { token, grant: key, proofs: [] };
|
|
211
|
+
return { token };
|
|
212
|
+
}
|
|
213
|
+
/** The dashboard cookie value, or false when nothing current matches. */
|
|
214
|
+
verifyDashboardToken(presented) {
|
|
215
|
+
if (presented === undefined || presented === null || presented === '')
|
|
216
|
+
return false;
|
|
217
|
+
if (this.dashboardCredential === null)
|
|
218
|
+
return false;
|
|
219
|
+
return tokensEqual(presented, this.dashboardCredential.token);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Take back a dashboard grant and the credential it became. An unspent
|
|
223
|
+
* grant is deleted. A spent one drops the credential and its proofs.
|
|
224
|
+
*/
|
|
225
|
+
revokeDashboardGrant(grant) {
|
|
226
|
+
if (grant === '')
|
|
227
|
+
return;
|
|
228
|
+
const key = findKey(this.dashboardGrants, grant);
|
|
229
|
+
if (key !== null)
|
|
230
|
+
this.dashboardGrants.delete(key);
|
|
231
|
+
if (this.dashboardCredential !== null && tokensEqual(this.dashboardCredential.grant, grant)) {
|
|
232
|
+
this.dashboardCredential = null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* A fresh proof for the current credential, or null when there is none.
|
|
237
|
+
* The ninth proof drops the oldest.
|
|
238
|
+
*/
|
|
239
|
+
issueDashboardProof() {
|
|
240
|
+
if (this.dashboardCredential === null)
|
|
241
|
+
return null;
|
|
242
|
+
const proof = generateToken();
|
|
243
|
+
this.dashboardCredential.proofs.push(proof);
|
|
244
|
+
while (this.dashboardCredential.proofs.length > DASHBOARD_PROOF_RING) {
|
|
245
|
+
this.dashboardCredential.proofs.shift();
|
|
246
|
+
}
|
|
247
|
+
return proof;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Whether `presented` is one of the proofs still in the ring. The compare
|
|
251
|
+
* hashes both strings, so a wrong proof of the same length takes the same
|
|
252
|
+
* path as a right one.
|
|
253
|
+
*/
|
|
254
|
+
acceptsDashboardProof(presented) {
|
|
255
|
+
if (presented === undefined || presented === null || presented === '')
|
|
256
|
+
return false;
|
|
257
|
+
if (this.dashboardCredential === null)
|
|
258
|
+
return false;
|
|
259
|
+
return this.dashboardCredential.proofs.some((proof) => tokensEqual(presented, proof));
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Verify a bearer token. Only the client token authenticates this way:
|
|
263
|
+
* viewer credentials are cookie-borne and session-scoped, and are checked
|
|
264
|
+
* with `verifyStreamToken`. The dashboard cookie is checked with
|
|
265
|
+
* `verifyDashboardToken`.
|
|
266
|
+
*/
|
|
267
|
+
verify(presented) {
|
|
268
|
+
if (presented === undefined || presented === null || presented === '')
|
|
269
|
+
return null;
|
|
270
|
+
if (tokensEqual(presented, this.clientToken))
|
|
271
|
+
return { kind: 'client' };
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
pruneExpired(now) {
|
|
275
|
+
for (const [token, grant] of this.grants) {
|
|
276
|
+
if (grant.expiresAt <= now)
|
|
277
|
+
this.grants.delete(token);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
pruneExpiredDashboard(now) {
|
|
281
|
+
for (const [token, grant] of this.dashboardGrants) {
|
|
282
|
+
if (grant.expiresAt <= now)
|
|
283
|
+
this.dashboardGrants.delete(token);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** Extract a bearer token from an Authorization header value. */
|
|
288
|
+
export function bearerToken(header) {
|
|
289
|
+
if (header === undefined)
|
|
290
|
+
return null;
|
|
291
|
+
const match = /^Bearer\s+(\S+)$/i.exec(header);
|
|
292
|
+
return match?.[1] ?? null;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The viewer's cookie name. One name, but each is written with the session's
|
|
296
|
+
* own `Path`, so a browser watching several sessions keeps their credentials
|
|
297
|
+
* apart and sends only the one whose path matches the socket being opened.
|
|
298
|
+
*/
|
|
299
|
+
export const VIEWER_COOKIE = 'sp_viewer';
|
|
300
|
+
/**
|
|
301
|
+
* Every value carried under `name` in a Cookie header, in order, with its
|
|
302
|
+
* percent-escapes decoded. More than one is possible: cookies ignore ports,
|
|
303
|
+
* so anything served from 127.0.0.1 can set a same-named cookie beside the
|
|
304
|
+
* daemon's own, and the caller tries each rather than trusting the first. A
|
|
305
|
+
* value whose escapes do not decode is skipped rather than thrown on.
|
|
306
|
+
*/
|
|
307
|
+
export function cookieValues(header, name) {
|
|
308
|
+
if (header === undefined)
|
|
309
|
+
return [];
|
|
310
|
+
const values = [];
|
|
311
|
+
for (const part of header.split(';')) {
|
|
312
|
+
const at = part.indexOf('=');
|
|
313
|
+
if (at === -1)
|
|
314
|
+
continue;
|
|
315
|
+
if (part.slice(0, at).trim() !== name)
|
|
316
|
+
continue;
|
|
317
|
+
try {
|
|
318
|
+
values.push(decodeURIComponent(part.slice(at + 1).trim()));
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
// Not a value this daemon ever set. Ignored, never fatal.
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return values;
|
|
325
|
+
}
|
|
326
|
+
/** The first value carried under `name`, or null. */
|
|
327
|
+
export function cookieValue(header, name) {
|
|
328
|
+
return cookieValues(header, name)[0] ?? null;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The `Set-Cookie` value delivering a stream credential.
|
|
332
|
+
*
|
|
333
|
+
* `HttpOnly` keeps it out of reach of page scripts, `SameSite=Strict` stops
|
|
334
|
+
* any other site's navigation carrying it and the per-session `Path` means a
|
|
335
|
+
* credential for one session is never even sent on another's socket. No
|
|
336
|
+
* `Max-Age`: it should die with the browsing session, not linger on disk.
|
|
337
|
+
* No `Secure`, deliberately: the daemon is loopback-only http, and a
|
|
338
|
+
* `Secure` cookie would simply never be stored.
|
|
339
|
+
*/
|
|
340
|
+
export function viewerCookie(sessionId, streamToken) {
|
|
341
|
+
return (`${VIEWER_COOKIE}=${encodeURIComponent(streamToken)}` +
|
|
342
|
+
`; Path=/sessions/${encodeURIComponent(sessionId)}` +
|
|
343
|
+
'; HttpOnly; SameSite=Strict');
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* The dashboard's cookie name. One credential for the dashboard, so one
|
|
347
|
+
* path: `/`. Cookies ignore ports, and `cookieValues` tries every value.
|
|
348
|
+
*/
|
|
349
|
+
export const DASHBOARD_COOKIE = 'sp_dash';
|
|
350
|
+
/**
|
|
351
|
+
* The `Set-Cookie` value delivering the dashboard credential.
|
|
352
|
+
*
|
|
353
|
+
* `HttpOnly` keeps it out of `document.cookie`. `SameSite=Strict` stops any
|
|
354
|
+
* other site's navigation carrying it. No `Max-Age`: it dies with the
|
|
355
|
+
* browsing session. No `Secure`: the daemon is loopback-only http, and a
|
|
356
|
+
* `Secure` cookie would never be stored. No `Domain`: it stays host-only.
|
|
357
|
+
*/
|
|
358
|
+
export function dashboardCookie(token) {
|
|
359
|
+
return `${DASHBOARD_COOKIE}=${encodeURIComponent(token)}; Path=/; HttpOnly; SameSite=Strict`;
|
|
360
|
+
}
|
|
361
|
+
/** The proof inside `sp-csrf.<64 hex>`, or null when the protocol is not that. */
|
|
362
|
+
export function dashboardProofFromProtocol(protocol) {
|
|
363
|
+
const match = /^sp-csrf\.([0-9a-f]{64})$/.exec(protocol);
|
|
364
|
+
return match?.[1] ?? null;
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=auth.js.map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