Skip to content

Commit 16f3794

Browse files
authored
Merge pull request #691 from supabase/INC-475/FUNC/hotfix/safe-url-construction
fix(deno_telemetry): guard against malformed request URLs in span attrs
2 parents ec2b443 + 1a07a62 commit 16f3794

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

vendor/deno_telemetry/util.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ export function updateSpanFromRequest(span: Span, request: Request) {
99
span.updateName(request.method);
1010

1111
span.setAttribute("http.request.method", request.method);
12-
const url = new URL(request.url);
1312
span.setAttribute("url.full", request.url);
14-
span.setAttribute(
15-
"url.scheme",
16-
StringPrototypeSlice(url.protocol, 0, -1),
17-
);
18-
span.setAttribute("url.path", url.pathname);
19-
span.setAttribute("url.query", StringPrototypeSlice(url.search, 1));
13+
// Malformed URLs (e.g. invalid hosts from internet scanners) would otherwise
14+
// throw here and crash the request handler before it can respond. Record the
15+
// raw URL above and skip the parsed attributes when parsing fails.
16+
try {
17+
const url = new URL(request.url);
18+
span.setAttribute(
19+
"url.scheme",
20+
StringPrototypeSlice(url.protocol, 0, -1),
21+
);
22+
span.setAttribute("url.path", url.pathname);
23+
span.setAttribute("url.query", StringPrototypeSlice(url.search, 1));
24+
} catch {
25+
span.setAttribute("url.parse_error", "true");
26+
}
2027
}
2128

2229
export function updateSpanFromResponse(span: Span, response: Response) {

0 commit comments

Comments
 (0)