@nirzon-islam/omega-fca 0.1.6-rc.1 → 0.1.6-rc.2

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/README.md CHANGED
@@ -154,3 +154,8 @@ npm run capture:browser
154
154
  Android/Termux: run `bash tools/termux-capture-setup.sh`, pair/connect ADB Wireless debugging, forward Chrome's DevTools socket, then run `npm run capture:browser -- --cdp http://127.0.0.1:9222`. Lemur/other browser compatibility is not assumed; verify the CDP endpoint first.
155
155
 
156
156
  The browser runs locally; it is not remotely visible to ChatGPT. The default report omits cookies, query strings, request/response bodies, and binary frame contents. An explicit `--save-private-frames` option stores raw WebSocket frames locally for owner-only inspection; those files may contain secrets or private messages and must not be shared unredacted.
157
+
158
+
159
+ ### Session bootstrap redirect handling
160
+
161
+ The personal-session bootstrap follows up to five same-site HTTPS redirects on Facebook/Messenger hosts, preserving rotated cookies between hops. Login and checkpoint redirects remain authentication failures, and redirects to unrelated hosts are rejected.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nirzon-islam/omega-fca",
3
- "version": "0.1.6-rc.1",
3
+ "version": "0.1.6-rc.2",
4
4
  "description": "OmegA Bot Facebook integration library, developed and maintained by NirZon",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -205,23 +205,48 @@ async function createPersonalSession({
205
205
 
206
206
  try {
207
207
  const bootstrapStartedAt = Date.now();
208
- const bootstrapResponse = await fetchImpl(FACEBOOK_ORIGIN + "/", {
209
- method: "GET",
210
- redirect: "manual",
211
- headers: {
212
- accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
213
- "accept-language": "en-US,en;q=0.9",
214
- cookie: jar.getCookieHeader(FACEBOOK_ORIGIN + "/"),
215
- "user-agent": userAgent
216
- },
217
- signal: controller.signal
218
- });
219
-
220
- const response = bootstrapResponse;
221
- const { accepted: bootstrapCookies, deletions: bootstrapDeletions } = collectResponseCookies(response, new URL(FACEBOOK_ORIGIN + "/"));
222
- if (bootstrapCookies.length) jar.setCookies(bootstrapCookies);
223
- if (bootstrapDeletions.length) jar.deleteCookies(bootstrapDeletions);
224
- emitDiagnostic({ phase: "response", request: { url: FACEBOOK_ORIGIN + "/", method: "GET" }, response: { status: response.status, contentType: response.headers?.get?.("content-type") || "", bodyBytes: Number(response.headers?.get?.("content-length") || 0) }, durationMs: Date.now() - bootstrapStartedAt });
208
+ const bootstrapHeaders = {
209
+ accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
210
+ "accept-language": "en-US,en;q=0.9",
211
+ "user-agent": userAgent
212
+ };
213
+ let bootstrapUrl = new URL(FACEBOOK_ORIGIN + "/");
214
+ let response = null;
215
+ // Fetch-compatible clients must not silently treat Facebook's normal
216
+ // same-site locale/canonical redirects as an authentication failure.
217
+ // Follow only HTTPS redirects that remain on Facebook/Messenger hosts.
218
+ for (let redirectCount = 0; redirectCount <= 5; redirectCount++) {
219
+ const requestUrl = bootstrapUrl;
220
+ response = await fetchImpl(requestUrl, {
221
+ method: "GET",
222
+ redirect: "manual",
223
+ headers: { ...bootstrapHeaders, cookie: jar.getCookieHeader(requestUrl) },
224
+ signal: controller.signal
225
+ });
226
+ const { accepted, deletions } = collectResponseCookies(response, requestUrl);
227
+ if (accepted.length) jar.setCookies(accepted);
228
+ if (deletions.length) jar.deleteCookies(deletions);
229
+ emitDiagnostic({
230
+ phase: "response",
231
+ request: { url: requestUrl.origin + requestUrl.pathname, method: "GET" },
232
+ response: { status: response.status, contentType: response.headers?.get?.("content-type") || "", bodyBytes: Number(response.headers?.get?.("content-length") || 0) },
233
+ durationMs: Date.now() - bootstrapStartedAt
234
+ });
235
+ if (![301, 302, 303, 307, 308].includes(response.status)) break;
236
+ const location = response.headers?.get?.("location") || "";
237
+ const target = location ? new URL(location, requestUrl) : null;
238
+ if (target && /checkpoint|challenge/i.test(target.href)) break;
239
+ const targetPath = target?.pathname?.toLowerCase() || "";
240
+ if (target && (targetPath.includes("login.php") || targetPath === "/login" || targetPath.startsWith("/login/"))) break;
241
+ if (!target || target.protocol !== "https:" ||
242
+ !/(^|\.)facebook\.com$|(^|\.)messenger\.com$/.test(target.hostname)) {
243
+ throw sessionError("Facebook redirected the session validation to an unsupported destination", "FCA_UNEXPECTED_REDIRECT", "error");
244
+ }
245
+ if (redirectCount === 5) {
246
+ throw sessionError("Facebook exceeded the session validation redirect limit", "FCA_REDIRECT_LIMIT", "error");
247
+ }
248
+ bootstrapUrl = target;
249
+ }
225
250
  if (response.status >= 500) {
226
251
  throw sessionError("Facebook is temporarily unavailable while validating the session", "FCA_UPSTREAM_UNAVAILABLE", "error");
227
252
  }