@nirzon-islam/omega-fca 0.1.5 → 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 +5 -0
- package/index.js +2 -2
- package/package.json +1 -1
- package/src/api/client.js +13 -3
- package/src/auth/personalSession.js +42 -18
- package/src/network/cookieJar.js +1 -1
- package/src/security/cookies.js +3 -2
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/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const { ConnectionSupervisor } = require("./src/runtime/connection");
|
|
|
10
10
|
const { EventDispatcher } = require("./src/events/dispatcher");
|
|
11
11
|
const { CookieJar } = require("./src/network/cookieJar");
|
|
12
12
|
const { createRequestClient, retryAfterMs, isRetryableStatus } = require("./src/network/requestClient");
|
|
13
|
-
const { createPersonalSession, detectSessionChallenge, extractIdentity, extractFacebookTokens
|
|
13
|
+
const { createPersonalSession, detectSessionChallenge, extractIdentity, extractFacebookTokens } = require("./src/auth/personalSession");
|
|
14
14
|
const { createAuthenticationAttempt, AUTHENTICATION_ATTEMPT_STATES } = require("./src/auth/authenticationAttempt");
|
|
15
15
|
const { parseAccountText, loadAccountConfig } = require("./src/auth/accountConfig");
|
|
16
16
|
const { generateTotp } = require("./src/auth/totp");
|
|
@@ -44,7 +44,7 @@ module.exports = {
|
|
|
44
44
|
normalizeCookies, validateSessionCookies, parseCookieHeader, parseNetscapeCookies,
|
|
45
45
|
redactSecrets, createDiagnosticRecorder, classifySessionState, describeError, encryptSession, decryptSession,
|
|
46
46
|
saveSession, loadSession, deleteSession, ConnectionSupervisor, EventDispatcher,
|
|
47
|
-
CookieJar, createRequestClient, retryAfterMs, isRetryableStatus, createPersonalSession, detectSessionChallenge, extractIdentity, extractFacebookTokens,
|
|
47
|
+
CookieJar, createRequestClient, retryAfterMs, isRetryableStatus, createPersonalSession, detectSessionChallenge, extractIdentity, extractFacebookTokens,
|
|
48
48
|
createAuthenticationAttempt, AUTHENTICATION_ATTEMPT_STATES,
|
|
49
49
|
parseAccountText, loadAccountConfig, generateTotp,
|
|
50
50
|
normalizeFacebookResponse, stripFacebookJsonPrefix, createFacebookError,
|
package/package.json
CHANGED
package/src/api/client.js
CHANGED
|
@@ -105,11 +105,22 @@ function createClient({ authenticate, options = {}, reconnect = {}, license = {}
|
|
|
105
105
|
// cookies, challenge answers, or tokens. Classify privately, then
|
|
106
106
|
// expose only a fixed safe error to the application.
|
|
107
107
|
const sessionState = classifySessionState(caught);
|
|
108
|
+
// Keep authentication failures distinct from failures that occur
|
|
109
|
+
// after AppState validation (for example MQTT CONNACK/SUBACK or
|
|
110
|
+
// WebSocket setup). Only allowlist stable, non-secret FCA codes;
|
|
111
|
+
// never forward provider messages or arbitrary error properties.
|
|
112
|
+
const safeProviderCode = typeof caught?.code === "string" &&
|
|
113
|
+
/^FCA_(?:MQTT_[A-Z0-9_]+|WS_[A-Z0-9_]+|SESSION_[A-Z0-9_]+|CHALLENGE_LIMIT|UPSTREAM_UNAVAILABLE|RESPONSE_TOO_LARGE)$/.test(caught.code)
|
|
114
|
+
? caught.code : null;
|
|
115
|
+
const isRealtimeFailure = safeProviderCode &&
|
|
116
|
+
(safeProviderCode.startsWith("FCA_MQTT_") || safeProviderCode.startsWith("FCA_WS_"));
|
|
108
117
|
const error = new Error(sessionState === "checkpoint"
|
|
109
118
|
? "Facebook requires the account owner to complete a checkpoint"
|
|
110
119
|
: sessionState === "logged_out"
|
|
111
120
|
? "The Facebook session has expired; supply a fresh authorized AppState"
|
|
112
|
-
:
|
|
121
|
+
: isRealtimeFailure
|
|
122
|
+
? "Facebook session was accepted, but Messenger realtime setup failed (" + safeProviderCode + ")"
|
|
123
|
+
: "Authentication failed; inspect provider diagnostics securely");
|
|
113
124
|
if (sessionState === "checkpoint") {
|
|
114
125
|
error.code = "FCA_CHECKPOINT_REQUIRED";
|
|
115
126
|
error.sessionState = sessionState;
|
|
@@ -119,8 +130,7 @@ function createClient({ authenticate, options = {}, reconnect = {}, license = {}
|
|
|
119
130
|
error.sessionState = sessionState;
|
|
120
131
|
error.retryable = false;
|
|
121
132
|
} else {
|
|
122
|
-
error.code =
|
|
123
|
-
? "FCA_CHALLENGE_LIMIT" : "FCA_AUTHENTICATION_FAILED";
|
|
133
|
+
error.code = safeProviderCode || "FCA_AUTHENTICATION_FAILED";
|
|
124
134
|
error.retryable = typeof caught?.retryable === "boolean" ? caught.retryable : true;
|
|
125
135
|
}
|
|
126
136
|
lastConnectError = error;
|
|
@@ -110,7 +110,6 @@ function extractRealtimeConfig(html) {
|
|
|
110
110
|
}
|
|
111
111
|
return Object.freeze({ endpoint: null, region: null, lastSeqId: null });
|
|
112
112
|
}
|
|
113
|
-
|
|
114
113
|
function collectResponseCookies(response, requestUrl) {
|
|
115
114
|
const raw = typeof response.headers?.getSetCookie === "function"
|
|
116
115
|
? response.headers.getSetCookie()
|
|
@@ -206,23 +205,48 @@ async function createPersonalSession({
|
|
|
206
205
|
|
|
207
206
|
try {
|
|
208
207
|
const bootstrapStartedAt = Date.now();
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
+
}
|
|
226
250
|
if (response.status >= 500) {
|
|
227
251
|
throw sessionError("Facebook is temporarily unavailable while validating the session", "FCA_UPSTREAM_UNAVAILABLE", "error");
|
|
228
252
|
}
|
package/src/network/cookieJar.js
CHANGED
|
@@ -53,7 +53,7 @@ class CookieJar {
|
|
|
53
53
|
const matches = this.cookies.filter(cookie => {
|
|
54
54
|
if (cookie.expires) {
|
|
55
55
|
const expiry = cookie.expires instanceof Date ? cookie.expires.getTime()
|
|
56
|
-
: typeof cookie.expires === "number" ? cookie.expires * 1000
|
|
56
|
+
: typeof cookie.expires === "number" ? (cookie.expires > 1e12 ? cookie.expires : cookie.expires * 1000)
|
|
57
57
|
: Date.parse(cookie.expires);
|
|
58
58
|
if (Number.isFinite(expiry) && expiry > 0 && expiry <= now) return false;
|
|
59
59
|
}
|
package/src/security/cookies.js
CHANGED
|
@@ -40,7 +40,7 @@ function normalizeCookies(input) {
|
|
|
40
40
|
value: item.value,
|
|
41
41
|
domain,
|
|
42
42
|
path,
|
|
43
|
-
hostOnly: item.hostOnly === undefined ?
|
|
43
|
+
hostOnly: item.hostOnly === undefined ? false : Boolean(item.hostOnly),
|
|
44
44
|
secure: Boolean(item.secure),
|
|
45
45
|
httpOnly: Boolean(item.httpOnly),
|
|
46
46
|
...(typeof item.sameSite === "string" ? { sameSite: item.sameSite } : {}),
|
|
@@ -68,7 +68,8 @@ function parseCookieHeader(header) {
|
|
|
68
68
|
if (index <= 0) throw new TypeError("Malformed cookie header");
|
|
69
69
|
return { key: part.slice(0, index).trim(), value: part.slice(index + 1).trim(), domain: "facebook.com", path: "/", hostOnly: true };
|
|
70
70
|
});
|
|
71
|
-
|
|
71
|
+
// A raw Cookie header has no host-only metadata. Treat imported Facebook cookies as domain-scoped so they reach www.facebook.com as expected.
|
|
72
|
+
return normalizeCookies(entries.map(cookie => ({ ...cookie, hostOnly: false })));
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
function parseNetscapeCookies(text) {
|