Skip to main content

SKY-D230 · Security in code

Open redirect

An open redirect is a page that sends the browser to an address taken from the request, such as the ?next= parameter of a login form. SKY-D230 reports a redirect whose target request data can choose, including its host.

Languages
Python, TypeScript/JavaScript, Go, Java, Kotlin, C#
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Go engine ID
SKY-G220, reported as SKY-D230
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

An attacker sends a real link to your site, such as https://shop.example/login?next=https://shop-example.evil/. The victim sees your domain, signs in, and lands on a copy of your site that asks for their password or card again.

What Skylos flags

app/auth.py · PythonReported on line 10
from flask import Flask, redirect, request, session app = Flask(__name__)  @app.post("/login")def login():    session["user"] = request.form["user"]    next_url = request.args.get("next", "/")    return redirect(next_url)

What Skylos leaves alone

app/orders.py · Python
from flask import Flask, redirect, request, url_for app = Flask(__name__)  @app.post("/orders/reorder")def reorder():    order_id = request.form["order_id"]    return redirect(url_for("order_detail", order_id=order_id))

Why Skylos leaves it alone

The request value only fills a parameter of url_for(), Flask's route builder, which always returns a path on this site. Skylos treats a target that starts with url_for() or Django's reverse() as internal.

More languages

TypeScript

Flagged

src/auth.ts · TypeScriptReported on line 7
import express from "express"; const app = express(); app.get("/login/done", (req, res) => {  const next = String(req.query.next ?? "/");  res.redirect(next);});

Not flagged

src/orders.ts · TypeScript
import express from "express"; const app = express(); app.get("/orders/:id", (req, res) => {  res.redirect(`/orders/${encodeURIComponent(req.params.id)}/summary`);});

Why Skylos leaves it alone

The target starts with the fixed path /orders/, so the request value can change which order page opens but never the site.

Go

Flagged

main.go · GoReported on line 7
package main import "net/http" func loginDone(w http.ResponseWriter, r *http.Request) {	next := r.URL.Query().Get("next")	http.Redirect(w, r, next, http.StatusFound)} func main() {	http.HandleFunc("/login/done", loginDone)}
go.mod · Text
module example.com/login go 1.22

Not flagged

main.go · Go
package main import "net/http" func loginDone(w http.ResponseWriter, r *http.Request) {	next := r.URL.Query().Get("next")	http.Redirect(w, r, "/welcome?from="+next, http.StatusFound)} func main() {	http.HandleFunc("/login/done", loginDone)}

go.mod: same as in the flagged example.

Why Skylos leaves it alone

The request value comes after a literal ?, so it only lands in the query string of a fixed path.

How Skylos decides

  1. Runs with --danger. Python: redirect(), HttpResponseRedirect and HttpResponsePermanentRedirect are reported when the first argument carries user data: request.args.get(…), other request.* reads, input() or a function parameter.
  2. Python: RedirectResponse, the HTTPFound family and a Location header (headers={"Location": url}, response.headers["Location"] = url) need a value read from the request to reach the target; a plain function parameter is not enough there.
  3. Python skips a target that starts with url_for() or reverse(), a fixed first path segment such as "/orders/" + slug (a slash and then a letter or digit), or "/?" or "/#". Inside an if, a name compared with == to a string literal, or tested with in against a literal list, tuple or set of strings, is clean in the branch where the test proves it; so is the URL in the passing branch of Django's url_has_allowed_host_and_scheme(). A startswith("/") or netloc check does not count, because //evil.example passes both.
  4. TypeScript and JavaScript: any .redirect(x) call whose first argument is not a string, template literal or number is reported, unless x starts with a fixed relative path or scheme://host/, or is built only from fixed text and process.env values. Request data does not have to be proven. Inside an Express, Koa, Next.js or similar handler, request data that can choose the host through res.redirect(), NextResponse.redirect(), res.location() or a Location header is reported too, template literals included.
  5. Go (from the Go engine as SKY-G220): request data in the target of http.Redirect, Gin and Echo c.Redirect or Fiber c.Redirect().To(), unless it comes after a literal ? or #, or the value was parsed with url.Parse and its scheme and host were checked before the redirect.
  6. Java and Kotlin: request data reaching sendRedirect(), RedirectView, Ktor respondRedirect() or a Spring "redirect:" + value view name, unless a fixed prefix pins the host. C#: request data in Redirect() and its variants or Response.Redirect(), unless guarded by Url.IsLocalUrl().

How to fix it

Only redirect to places you chose. Compare the value with a literal list of allowed paths, build the target with url_for() or reverse(), or in Django check it with url_has_allowed_host_and_scheme(). A startswith("/") test is not enough: //evil.example starts with a slash and leaves the site.

app/auth.py · Python · the fix, against the flagged file
from flask import Flask, redirect, request, session app = Flask(__name__)  @app.post("/login")def login():    session["user"] = request.form["user"]    next_url = request.args.get("next", "/")Added:     if next_url not in {"/", "/account", "/orders"}:Added:         next_url = "/"    return redirect(next_url)

When it can be wrong

  • In Python, an allowlist kept in a named constant, such as if next_url not in ALLOWED_PAGES:, is not recognised; only a list, tuple or set written in the test counts.
  • A Python helper such as def back_to(page): return redirect(page) is reported, because function parameters count as user data for redirect().
  • In TypeScript and JavaScript, res.redirect(settings.homeUrl) is reported even when the value comes from your own configuration: the syntactic check does not look for request data.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Mark the reported line and say why the target is safe.

    Python
    return redirect(page)  # skylos: ignore[SKY-D230] page is one of our route names
  • Accept existing findings with skylos baseline ., then scan with --baseline. Entries match by file and line.

  • [tool.skylos] ignore = ["SKY-D230"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.