unbrowse 2.8.1 → 2.8.3

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/cli.js CHANGED
@@ -6116,6 +6116,10 @@ async function interactiveLogin(url, domain) {
6116
6116
  const vaultKey = `auth:${getRegistrableDomain(targetDomain)}`;
6117
6117
  await storeCredential(vaultKey, JSON.stringify({ cookies: storableCookies }));
6118
6118
  log("auth", `stored ${storableCookies.length} cookies under ${vaultKey}`);
6119
+ try {
6120
+ await authProfileSave(tabId, targetDomain.replace(/^www\./, ""));
6121
+ log("auth", `saved Kuri auth profile for ${targetDomain}`);
6122
+ } catch {}
6119
6123
  return { success: true, domain: targetDomain, cookies_stored: storableCookies.length };
6120
6124
  } finally {
6121
6125
  if (prevHeadless !== undefined)
@@ -11157,12 +11161,11 @@ async function executeEndpoint(skill, endpoint, params = {}, projection, options
11157
11161
  return `${c.name}=${v}`;
11158
11162
  }).join("; ");
11159
11163
  headers["cookie"] = cookieStr;
11160
- if (!headers["x-csrf-token"] && !headers["x-xsrf-token"]) {
11161
- const csrfCookie = cookies.find((c) => /^(ct0|csrf_token|_csrf|csrftoken|XSRF-TOKEN|_xsrf)$/i.test(c.name));
11162
- if (csrfCookie) {
11163
- const v = csrfCookie.value.startsWith('"') && csrfCookie.value.endsWith('"') ? csrfCookie.value.slice(1, -1) : csrfCookie.value;
11164
- headers["x-csrf-token"] = v;
11165
- }
11164
+ const csrfCookie = cookies.find((c) => /^(ct0|csrf_token|_csrf|csrftoken|XSRF-TOKEN|_xsrf)$/i.test(c.name));
11165
+ if (csrfCookie) {
11166
+ const v = csrfCookie.value.startsWith(") && csrfCookie.value.endsWith(") ? csrfCookie.value.slice(1, -1) : csrfCookie.value;
11167
+ headers["x-csrf-token"] = v;
11168
+ headers["x-xsrf-token"] = v;
11166
11169
  }
11167
11170
  }
11168
11171
  if (endpoint.csrf_plan && cookies.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unbrowse",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
4
4
  "description": "Reverse-engineer any website into reusable API skills. Zero-dep single binary with embedded browser engine.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -142,6 +142,12 @@ export async function interactiveLogin(
142
142
  await storeCredential(vaultKey, JSON.stringify({ cookies: storableCookies }));
143
143
  log("auth", `stored ${storableCookies.length} cookies under ${vaultKey}`);
144
144
 
145
+ // Also save as Kuri auth profile so browse commands (go/snap/click) have auth
146
+ try {
147
+ await kuri.authProfileSave(tabId, targetDomain.replace(/^www\./, ""));
148
+ log("auth", `saved Kuri auth profile for ${targetDomain}`);
149
+ } catch { /* non-fatal — Kuri auth profile save is best-effort */ }
150
+
145
151
  return { success: true, domain: targetDomain, cookies_stored: storableCookies.length };
146
152
  } finally {
147
153
  // Restore headless setting so subsequent captures run headless
@@ -1880,15 +1880,15 @@ export async function executeEndpoint(
1880
1880
  headers["cookie"] = cookieStr;
1881
1881
 
1882
1882
  // CSRF token auto-detection (bird pattern): many sites require CSRF tokens
1883
- // as both a cookie AND a header. Detect common patterns and replay them.
1884
- if (!headers["x-csrf-token"] && !headers["x-xsrf-token"]) {
1885
- const csrfCookie = cookies.find((c) =>
1886
- /^(ct0|csrf_token|_csrf|csrftoken|XSRF-TOKEN|_xsrf)$/i.test(c.name)
1887
- );
1888
- if (csrfCookie) {
1889
- const v = csrfCookie.value.startsWith('"') && csrfCookie.value.endsWith('"') ? csrfCookie.value.slice(1, -1) : csrfCookie.value;
1890
- headers["x-csrf-token"] = v;
1891
- }
1883
+ // as both a cookie AND a header. The cookie value is always fresher than
1884
+ // any stored vault header, so it ALWAYS overrides.
1885
+ const csrfCookie = cookies.find((c) =>
1886
+ /^(ct0|csrf_token|_csrf|csrftoken|XSRF-TOKEN|_xsrf)$/i.test(c.name)
1887
+ );
1888
+ if (csrfCookie) {
1889
+ const v = csrfCookie.value.startsWith(') && csrfCookie.value.endsWith(') ? csrfCookie.value.slice(1, -1) : csrfCookie.value;
1890
+ headers["x-csrf-token"] = v;
1891
+ headers["x-xsrf-token"] = v;
1892
1892
  }
1893
1893
  }
1894
1894