Skip to content

Commit 07feab5

Browse files
committed
fix(security): validate mothership proxy endpoint to block path traversal
1 parent 556e0fd commit 07feab5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • apps/sim/app/api/admin/mothership

apps/sim/app/api/admin/mothership/route.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ function getMothershipUrl(environment: string): string | null {
1616
return ENV_URLS[environment] ?? null
1717
}
1818

19+
const ENDPOINT_PATTERN = /^[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*$/
20+
21+
function isValidEndpoint(endpoint: string): boolean {
22+
if (!endpoint) return false
23+
if (endpoint.includes('..')) return false
24+
return ENDPOINT_PATTERN.test(endpoint)
25+
}
26+
1927
async function isAdminRequestAuthorized() {
2028
const session = await getSession()
2129
if (!session?.user?.id) return false
@@ -57,6 +65,10 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
5765
return NextResponse.json({ error: 'endpoint query param required' }, { status: 400 })
5866
}
5967

68+
if (!isValidEndpoint(endpoint)) {
69+
return NextResponse.json({ error: 'invalid endpoint' }, { status: 400 })
70+
}
71+
6072
const baseUrl = getMothershipUrl(environment)
6173
if (!baseUrl) {
6274
return NextResponse.json(
@@ -108,6 +120,10 @@ export const GET = withRouteHandler(async (req: NextRequest) => {
108120
return NextResponse.json({ error: 'endpoint query param required' }, { status: 400 })
109121
}
110122

123+
if (!isValidEndpoint(endpoint)) {
124+
return NextResponse.json({ error: 'invalid endpoint' }, { status: 400 })
125+
}
126+
111127
const baseUrl = getMothershipUrl(environment)
112128
if (!baseUrl) {
113129
return NextResponse.json(

0 commit comments

Comments
 (0)