cauthy-auth 0.38.2 → 0.39.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/dist/index.mjs CHANGED
@@ -1506,13 +1506,13 @@ function createCauthy(given = {}) {
1506
1506
  return null;
1507
1507
  }
1508
1508
  }
1509
- const clientIp = given.clientIp ?? ((request) => request.headers.get("x-forwarded-for")?.split(",").pop()?.trim() || void 0);
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
1518
  noProofUntil = Date.now() + 5 * 6e4;
@@ -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() {