Skip to content

Commit a50380d

Browse files
committed
chore(gates): simplify provider proxy route admission
1 parent a6a659d commit a50380d

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎test/integration/provider-scenarios/harness-proxy.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
/^\/sessions\/(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2})+\/requests\/(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2})+\/diagnostics$/.test(
188-
route,
189-
);
190-
const isArtifactList = method === 'GET' && (route === '/artifacts' || route === '/artifacts/');
191-
const isArtifact = method === 'GET' && /^\/artifacts\/[0-9a-f-]+$/i.test(route);
192-
const isUpload =
193-
(method === 'POST' && ['/upload/preflight', '/upload/finalize'].includes(route)) ||
194-
(method === 'PUT' && /^\/upload\/direct\/[0-9a-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 /^\/upload\/direct\/[0-9a-f-]+$/i.test(route);
193+
case 'GET':
194+
return (
195+
['/artifacts', '/artifacts/'].includes(route) ||
196+
/^\/artifacts\/[0-9a-f-]+$/i.test(route) ||
197+
/^\/sessions\/(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2})+\/requests\/(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2})+\/diagnostics$/.test(
198+
route,
199+
)
200+
);
201+
default:
202+
return false;
203+
}
204+
}
205+
199206
async 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

Comments
 (0)