bugger.
All challenges/TypeScriptmediumthe-url-that-escapes-its-origin-v1
THE INVESTIGATION

The URL that escapes its origin

A credentialed API client sends its key to an unexpected destination.

Real incidentsURL originsRegression testing

What’s going wrong

Input is an array of at most 100 {base, url} rows. base is a valid absolute HTTP(S) URL without credentials, with a trailing slash and no query or fragment. url is a valid URL reference accepted by the WHATWG URL constructor, at most 300 characters. Resolve url against base, then allow the planned request only if its normalized origin equals base.origin, its scheme is http: or https:, and it contains no username or password. Output {url: normalizedHref, sendKey: true} for an allowed request or {blocked: true} otherwise. Same-origin absolute URLs and path traversal within that origin are allowed by this origin-only policy. Preserve query and fragment in normalizedHref. Do not perform network requests.

Expected behavior

Validate a resolved URL before attaching credentials.

Reproduction

01 Absolute destination changes the origin
[{"base":"https://api.example.test/v1/","url":"https://outside.example.test/collect"}]
[{"blocked":true}]
02 Relative request control
[{"base":"https://api.example.test/v1/","url":"users?limit=2"}]
[{"url":"https://api.example.test/v1/users?limit=2","sendKey":true}]
03 Same-origin absolute control
[{"base":"https://api.example.test/v1/","url":"https://api.example.test/status"}]
[{"url":"https://api.example.test/status","sendKey":true}]

Before you begin

  • TypeScript objects and arrays
  • URL origins and normalization

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.