@@ -16,6 +16,14 @@ function getMothershipUrl(environment: string): string | null {
1616 return ENV_URLS [ environment ] ?? null
1717}
1818
19+ const ENDPOINT_PATTERN = / ^ [ a - z A - Z 0 - 9 _ - ] + (?: \/ [ a - z A - Z 0 - 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+
1927async 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