Skip to content

Commit

Permalink
feat: allow users to disable SSRF or set a whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
coulsonpl committed Nov 6, 2024
1 parent 4f50dfa commit bd9970b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/(backend)/webapi/proxy/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextResponse } from 'next/server';
import fetch from 'node-fetch';
import { useAgent as ssrfAgent } from 'request-filtering-agent';
import { RequestFilteringAgentOptions, useAgent as ssrfAgent } from 'request-filtering-agent';

/**
* just for a proxy
Expand All @@ -9,7 +9,14 @@ export const POST = async (req: Request) => {
const url = await req.text();

try {
const res = await fetch(url, { agent: ssrfAgent(url) });
// https://www.npmjs.com/package/request-filtering-agent
const options: RequestFilteringAgentOptions = {
allowIPAddressList: process.env.SSRF_ALLOW_IP_ADDRESS_LIST?.split(',') || [],
allowMetaIPAddress: process.env.SSRF_ALLOW_META_IP_ADDRESS?.toLowerCase() === 'true',
allowPrivateIPAddress: process.env.SSRF_ALLOW_PRIVATE_IP_ADDRESS?.toLowerCase() === 'true',
denyIPAddressList: process.env.SSRF_DENY_IP_ADDRESS_LIST?.split(',') || [],
};
const res = await fetch(url, { agent: ssrfAgent(url, options) });

return new Response(await res.arrayBuffer(), { headers: { ...res.headers } });
} catch (err) {
Expand Down

0 comments on commit bd9970b

Please sign in to comment.