cauthy-auth 0.38.2 → 0.40.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/README.md +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1157,13 +1157,13 @@ function createCauthy(given = {}) {
|
|
|
1157
1157
|
return proto === "https" || proto === "http" ? `${proto}://${url.host}` : url.origin;
|
|
1158
1158
|
};
|
|
1159
1159
|
const attrs = (request, maxAge) => ({ secure: originOf(request).startsWith("https://"), maxAge });
|
|
1160
|
-
async function token(form) {
|
|
1160
|
+
async function token(form, proof = {}) {
|
|
1161
1161
|
const body2 = new URLSearchParams({ client_id: clientId, ...form });
|
|
1162
1162
|
if (clientSecret) body2.set("client_secret", clientSecret);
|
|
1163
1163
|
try {
|
|
1164
1164
|
const res = await doFetch(`${issuer}/v1/oauth/token`, {
|
|
1165
1165
|
method: "POST",
|
|
1166
|
-
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
|
|
1166
|
+
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json", ...proof },
|
|
1167
1167
|
body: body2
|
|
1168
1168
|
});
|
|
1169
1169
|
if (res.ok) return { ok: true, body: await res.json() };
|
|
@@ -1403,7 +1403,7 @@ function createCauthy(given = {}) {
|
|
|
1403
1403
|
code,
|
|
1404
1404
|
redirect_uri: `${originOf(request)}${basePath}/callback`,
|
|
1405
1405
|
code_verifier: flow.verifier
|
|
1406
|
-
});
|
|
1406
|
+
}, await passedOn(request));
|
|
1407
1407
|
const s = res.ok ? await stored(res.body) : null;
|
|
1408
1408
|
if (s === null) return failed(request, "exchange_failed");
|
|
1409
1409
|
return redirect(flow.returnTo, [...await write(request, s, had), writeCookie(flowCookie, "", attrs(request, 0)), writeCookie(againCookie, "", attrs(request, 0))]);
|
|
@@ -1506,16 +1506,16 @@ function createCauthy(given = {}) {
|
|
|
1506
1506
|
return null;
|
|
1507
1507
|
}
|
|
1508
1508
|
}
|
|
1509
|
-
const clientIp = given.clientIp ?? ((request) => request.headers.get("x-forwarded-for")?.split(",").
|
|
1509
|
+
const clientIp = given.clientIp ?? ((request) => request.headers.get("x-forwarded-for")?.split(",").map((a) => a.trim()).reverse().find((a) => a !== "" && !ownNetwork(a)));
|
|
1510
1510
|
let noProofUntil = 0;
|
|
1511
1511
|
async function passedOn(request) {
|
|
1512
1512
|
if (Date.now() < noProofUntil) return {};
|
|
1513
1513
|
const ip = clientIp(request);
|
|
1514
1514
|
try {
|
|
1515
|
-
const proof = { "x-cauthy-system-token": await ownSystem.token() };
|
|
1515
|
+
const proof = { "x-cauthy-system-token": await ownSystem.token(), "x-cauthy-app-origin": originOf(request) };
|
|
1516
1516
|
return ip ? { ...proof, "x-cauthy-client-ip": ip } : proof;
|
|
1517
1517
|
} catch {
|
|
1518
|
-
noProofUntil = Date.now() +
|
|
1518
|
+
noProofUntil = Date.now() + 3e4;
|
|
1519
1519
|
return {};
|
|
1520
1520
|
}
|
|
1521
1521
|
}
|
|
@@ -2417,6 +2417,10 @@ function legalOf(raw) {
|
|
|
2417
2417
|
consentPurposes: purposes.map((p) => ({ key: String(p.key ?? ""), label: String(p.label ?? ""), required: p.required === true }))
|
|
2418
2418
|
};
|
|
2419
2419
|
}
|
|
2420
|
+
function ownNetwork(address) {
|
|
2421
|
+
const a = address.toLowerCase();
|
|
2422
|
+
return /^(127\.|10\.|192\.168\.|169\.254\.|0\.)/.test(a) || /^172\.(1[6-9]|2\d|3[01])\./.test(a) || a === "::1" || /^f[cd]/.test(a) || /^fe[89ab]/.test(a) || a.startsWith("::ffff:127.") || a === "localhost";
|
|
2423
|
+
}
|
|
2420
2424
|
|
|
2421
2425
|
// src/connect.ts
|
|
2422
2426
|
function sessionSecret() {
|