Line data Source code
1 : import type { RouteLocation, RouteLocationRaw } from 'vue-router'
2 :
3 : import { reportError } from '@comfyorg/telemetry/reportError'
4 :
5 : /**
6 : * An unmatched path is attacker-supplied and unbounded, so it is truncated
7 : * before it reaches telemetry. It is not redacted: every route in this app is
8 : * a static literal with no parameter segments, and OAuth/share state travels
9 : * in the query string, which `to.path` excludes — so a path segment carries no
10 : * secret material, and the specific bad URL is the whole diagnostic value.
11 : */
12 2356 : const MAX_REPORTED_PATH_LENGTH = 128
13 :
14 : /**
15 : * Unknown paths redirect to root rather than hanging on the splash screen with
16 : * no route match. The global auth guard then routes unauthenticated users to
17 : * /cloud/login as normal.
18 : *
19 : * The Error message is deliberately static so every unmatched path groups into
20 : * one issue; the path itself rides along as context, where high cardinality is
21 : * cheap and a spike is still attributable.
22 : */
23 0 : export function unmatchedRouteRedirect(to: RouteLocation): RouteLocationRaw {
24 0 : reportError(new Error('Unmatched route'), {
25 : surface: 'platform',
26 : errorType: 'unmatched_route',
27 : level: 'warning',
28 : context: { path: to.path.slice(0, MAX_REPORTED_PATH_LENGTH) }
29 : })
30 :
31 0 : return '/'
32 : }
|