Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat(countryCheck): better protection against XFF spoofing (#2051)
Gergő Móricz22c98f5e85b0
diff --git a/apps/api/src/index.ts b/apps/api/src/index.tsindex eb16f451a..1aaa0bf38 100644--- a/apps/api/src/index.ts+++ b/apps/api/src/index.ts@@ -81,6 +81,10 @@ app.use(bodyParser.json({ limit: "10mb" }));app.use(cors()); // Add this line to enable CORS+if (process.env.EXPRESS_TRUST_PROXY) {+ app.set("trust proxy", parseInt(process.env.EXPRESS_TRUST_PROXY, 10));+}+const serverAdapter = new ExpressAdapter();serverAdapter.setBasePath(`/admin/${process.env.BULL_AUTH_KEY}/queues`);diff --git a/apps/api/src/routes/shared.ts b/apps/api/src/routes/shared.tsindex 1f677eb08..cac0dfca5 100644--- a/apps/api/src/routes/shared.ts+++ b/apps/api/src/routes/shared.ts@@ -204,24 +204,21 @@ export function countryCheck(if (!couldBeRestricted) {return next();}-- const _ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress || "";- const ip = Array.isArray(_ip) ? _ip[0] : _ip.split(",")[0];- if (!ip) {+ if (!req.ip) {logger.warn("IP address not found, unable to check country");return next();}- const country = geoip.lookup(ip);+ const country = geoip.lookup(req.ip);if (!country || !country.country) {- logger.warn("IP address country data not found", { ip });+ logger.warn("IP address country data not found", { ip: req.ip });return next();}const restricted = process.env.RESTRICTED_COUNTRIES?.split(",") ?? [];if (restricted.includes(country.country)) {- logger.warn("Denied access to restricted country", { ip, country: country.country, teamId: req.auth.team_id });+ logger.warn("Denied access to restricted country", { ip: req.ip, country: country.country, teamId: req.auth.team_id });return res.status(403).json({success: false,error: "Use of headers, actions, and the FIRE-1 agent is not allowed by default in your country. Please contact us at [email protected]",