@@ -180,22 +180,29 @@ function allowlistedUpstreamTarget(
180180 }
181181
182182 const route = target . pathname ;
183- const method = request . method ;
184- const isRpc = method === 'POST' && route === '/rpc' ;
185- const isDiagnostics =
186- method === 'GET' &&
187- / ^ \/ s e s s i o n s \/ (?: [ A - Z a - z 0 - 9 . _ ~ - ] | % [ 0 - 9 A - F a - f ] { 2 } ) + \/ r e q u e s t s \/ (?: [ A - Z a - z 0 - 9 . _ ~ - ] | % [ 0 - 9 A - F a - f ] { 2 } ) + \/ d i a g n o s t i c s $ / . test (
188- route ,
189- ) ;
190- const isArtifactList = method === 'GET' && ( route === '/artifacts' || route === '/artifacts/' ) ;
191- const isArtifact = method === 'GET' && / ^ \/ a r t i f a c t s \/ [ 0 - 9 a - f - ] + $ / i. test ( route ) ;
192- const isUpload =
193- ( method === 'POST' && [ '/upload/preflight' , '/upload/finalize' ] . includes ( route ) ) ||
194- ( method === 'PUT' && / ^ \/ u p l o a d \/ d i r e c t \/ [ 0 - 9 a - f - ] + $ / i. test ( route ) ) ;
195- if ( ! isRpc && ! isDiagnostics && ! isArtifactList && ! isArtifact && ! isUpload ) return undefined ;
183+ if ( ! isAllowedUpstreamRoute ( request . method , route ) ) return undefined ;
196184 return { path : route , route } ;
197185}
198186
187+ function isAllowedUpstreamRoute ( method : string | undefined , route : string ) : boolean {
188+ switch ( method ) {
189+ case 'POST' :
190+ return [ '/rpc' , '/upload/preflight' , '/upload/finalize' ] . includes ( route ) ;
191+ case 'PUT' :
192+ return / ^ \/ u p l o a d \/ d i r e c t \/ [ 0 - 9 a - f - ] + $ / i. test ( route ) ;
193+ case 'GET' :
194+ return (
195+ [ '/artifacts' , '/artifacts/' ] . includes ( route ) ||
196+ / ^ \/ a r t i f a c t s \/ [ 0 - 9 a - f - ] + $ / i. test ( route ) ||
197+ / ^ \/ s e s s i o n s \/ (?: [ A - Z a - z 0 - 9 . _ ~ - ] | % [ 0 - 9 A - F a - f ] { 2 } ) + \/ r e q u e s t s \/ (?: [ A - Z a - z 0 - 9 . _ ~ - ] | % [ 0 - 9 A - F a - f ] { 2 } ) + \/ d i a g n o s t i c s $ / . test (
198+ route ,
199+ )
200+ ) ;
201+ default :
202+ return false ;
203+ }
204+ }
205+
199206async function readRequestBody ( request : http . IncomingMessage ) : Promise < Buffer > {
200207 const chunks : Buffer [ ] = [ ] ;
201208 for await ( const chunk of request ) chunks . push ( Buffer . from ( chunk ) ) ;
0 commit comments