@ai-ecoverse/sliccy-browser 0.1.41 → 0.1.44

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/sliccy-browser",
3
- "version": "0.1.41",
4
- "description": "sliccy:browser for jsh, over CDP. Discovers Chrome via SLICC_CDP_URL, slicc browsers --json, DevToolsActivePort under slicc profiles (live /json/version must match the file's websocket path), then 127.0.0.1:9222. Discovered endpoints refuse seven/vault/extension/error pages.",
3
+ "version": "0.1.44",
4
+ "description": "sliccy:browser for jsh, over CDP. Discovers Chrome via SLICC_CDP_URL, slicc browsers --json, DevToolsActivePort under slicc profiles (live /json/version must match the file's websocket path), then 127.0.0.1:9222. Discovered endpoints refuse seven/vault/extension/error pages; pre-attach websocket frames are dropped with a one-time warning.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
package/src/browser.js CHANGED
@@ -16,6 +16,8 @@ export { REFUSAL, resolveCdpEndpoint, version };
16
16
 
17
17
  const LOAD_TIMEOUT_MS = 15000;
18
18
  const HELD_FRAMES = 100;
19
+ const UNKNOWN_SOCKET_WARNING =
20
+ 'browser.websocket: frames from sockets opened before the first attach are ignored in discovered mode; reload the tab or reconnect the socket after the first attach to make them visible';
19
21
  const RECORDER = `(() => {
20
22
  if (globalThis.__sliccWsSent) return true;
21
23
  const sent = [];
@@ -191,11 +193,24 @@ function dispatchFrame(message) {
191
193
  route(targetId, url, response.payloadData, () => true);
192
194
  return;
193
195
  }
194
- if (guarded) return;
196
+ if (guarded) {
197
+ noteUnknownDrop(targetId);
198
+ return;
199
+ }
195
200
  route(targetId, url, response.payloadData, (sub) => sub.urlMatch === undefined);
196
201
  holdFrame(message.sessionId, targetId, key, response.payloadData);
197
202
  }
198
203
 
204
+ function noteUnknownDrop(targetId) {
205
+ for (const sub of subscribers.values()) {
206
+ if (sub.targetId !== targetId) continue;
207
+ sub.dropped += 1;
208
+ if (sub.warnedUnknown) continue;
209
+ sub.warnedUnknown = true;
210
+ console.warn(UNKNOWN_SOCKET_WARNING);
211
+ }
212
+ }
213
+
199
214
  function route(targetId, url, raw, which) {
200
215
  if (guarded && (typeof url !== 'string' || isProtectedUrl(url))) return;
201
216
  for (const sub of subscribers.values()) {
@@ -719,6 +734,9 @@ function toInfo(sub) {
719
734
  function makeHandle(sub) {
720
735
  return {
721
736
  ...toInfo(sub),
737
+ get dropped() {
738
+ return sub.dropped;
739
+ },
722
740
  async update(patch = {}) {
723
741
  if (patch.urlMatch === null) {
724
742
  delete sub.urlMatch;
@@ -792,6 +810,8 @@ export const websocket = {
792
810
  forward: sink,
793
811
  createdAt: new Date().toISOString(),
794
812
  writing: Promise.resolve(),
813
+ dropped: 0,
814
+ warnedUnknown: false,
795
815
  };
796
816
  if (urlMatch !== undefined) {
797
817
  sub.urlMatch = urlMatch;
@@ -0,0 +1,14 @@
1
+ export const CREDENTIAL_ORIGIN_FLOOR = [
2
+ 'https://ims-na1.adobelogin.com',
3
+ 'https://ims-na1-stg1.adobelogin.com',
4
+ ];
5
+
6
+ export const CATALOG_CREDENTIAL_ORIGINS = {
7
+ origins: ['https://ims-na1.adobelogin.com', 'https://ims-na1-stg1.adobelogin.com'],
8
+ refusal: 'slicc: refused: this origin holds sign-in credentials',
9
+ };
10
+
11
+ export const CREDENTIAL_ORIGINS = {
12
+ origins: [...new Set([...CREDENTIAL_ORIGIN_FLOOR, ...CATALOG_CREDENTIAL_ORIGINS.origins])],
13
+ refusal: CATALOG_CREDENTIAL_ORIGINS.refusal,
14
+ };
package/src/guard.js CHANGED
@@ -1,9 +1,47 @@
1
- import { protectedOrigins } from './protected.js';
1
+ import { CREDENTIAL_ORIGINS as CREDENTIAL_ORIGIN_RULES } from './credential-origins.js';
2
+ import { credentialOrigins as credentialOriginsOf, protectedOrigins } from './protected.js';
2
3
  import { PROTECTED_ORIGINS } from './protected-origins.js';
3
4
 
4
5
  export const REFUSAL = PROTECTED_ORIGINS.refusal;
5
6
 
6
7
  const guard = protectedOrigins(PROTECTED_ORIGINS);
8
+ const credential = credentialOriginsOf(CREDENTIAL_ORIGIN_RULES);
9
+
10
+ export const CREDENTIAL_ORIGINS = CREDENTIAL_ORIGIN_RULES.origins;
11
+ export const CREDENTIAL_REFUSAL = CREDENTIAL_ORIGIN_RULES.refusal;
12
+
13
+ const credentialHosts = credential.hosts();
14
+
15
+ function coversCredential(domain) {
16
+ return domain.length > 0 && credentialHosts.some((host) => under(host, domain));
17
+ }
18
+
19
+ function credentialUrl(text) {
20
+ let host;
21
+ try {
22
+ host = hostOf(asHttp(text));
23
+ } catch {
24
+ return false;
25
+ }
26
+ if (host.startsWith('[') || /^[0-9.]+$/u.test(host)) return false;
27
+ const labels = host.split('.');
28
+ for (let at = 0; at < labels.length - 1; at += 1) {
29
+ if (coversCredential(labels.slice(at).join('.'))) return true;
30
+ }
31
+ return false;
32
+ }
33
+
34
+ export function credentialCookie(cookie) {
35
+ if (!cookie || typeof cookie !== 'object') return true;
36
+ if (typeof cookie.domain === 'string' && credential.cookieDomain(cookie.domain)) return true;
37
+ if (typeof cookie.url === 'string' && credentialUrl(cookie.url)) return true;
38
+ const key = cookie.partitionKey;
39
+ if (typeof key === 'string') return credential.topLevelSite(key);
40
+ if (key && typeof key === 'object' && typeof key.topLevelSite === 'string') {
41
+ return credential.topLevelSite(key.topLevelSite);
42
+ }
43
+ return false;
44
+ }
7
45
 
8
46
  function under(host, domain) {
9
47
  return host === domain || host.endsWith(`.${domain}`);
@@ -66,6 +104,7 @@ function siteProtected(site) {
66
104
 
67
105
  export function cookieProtected(cookie) {
68
106
  if (!cookie || typeof cookie !== 'object') return true;
107
+ if (credentialCookie(cookie)) return true;
69
108
  if (typeof cookie.domain === 'string' && guard.cookieDomain(cookie.domain)) return true;
70
109
  if (typeof cookie.url === 'string') {
71
110
  if (isProtectedUrl(cookie.url)) return true;
package/src/protected.js CHANGED
@@ -113,3 +113,52 @@ export function protectedOrigins(rules, extraOrigins = []) {
113
113
 
114
114
  return { url, target, cookieDomain, storageKey, unparseable, extensionFrame };
115
115
  }
116
+
117
+ export function credentialOrigins(rules) {
118
+ const hosts = (rules?.origins ?? [])
119
+ .map((text) => {
120
+ const u = parse(text);
121
+ return u?.host ? hostOf(u) : null;
122
+ })
123
+ .filter(Boolean);
124
+
125
+ const hostMatch = (text) => {
126
+ const u = parse(text);
127
+ if (!u || !['http', 'https'].includes(scheme(u))) return false;
128
+ const h = hostOf(u);
129
+ return hosts.includes(h);
130
+ };
131
+
132
+ const cookieDomain = (domain) => {
133
+ let d = String(domain ?? '').toLowerCase();
134
+ if (d.startsWith('.')) d = d.slice(1);
135
+ if (d.endsWith('.')) d = d.slice(0, -1);
136
+ if (d === '') return false;
137
+ return hosts.some((h) => under(h, d));
138
+ };
139
+
140
+ const topLevelSite = (text) => {
141
+ const u = parse(text);
142
+ if (!u || !['http', 'https'].includes(scheme(u))) return false;
143
+ const site = hostOf(u);
144
+ return hosts.some((h) => under(h, site));
145
+ };
146
+
147
+ const storageKey = (key) => {
148
+ const [first, ...rest] = String(key ?? '').split('^');
149
+ if (hostMatch(first)) return true;
150
+ return rest
151
+ .filter((p) => p.startsWith('0'))
152
+ .map((p) => p.slice(1))
153
+ .some((text) => topLevelSite(text));
154
+ };
155
+
156
+ return {
157
+ url: hostMatch,
158
+ cookieDomain,
159
+ topLevelSite,
160
+ storageKey,
161
+ hosts: () => [...hosts],
162
+ refusal: () => rules?.refusal ?? '',
163
+ };
164
+ }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '0.1.41';
1
+ export const version = '0.1.44';