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
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
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
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
import express from "express"; const app = express(); app.get("/login/done", (req, res) => { const next = String(req.query.next ?? "/"); res.redirect(next);});Not flagged
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
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)}module example.com/login go 1.22Not flagged
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)}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
- Runs with
--danger. Python:redirect(),HttpResponseRedirectandHttpResponsePermanentRedirectare reported when the first argument carries user data:request.args.get(…), otherrequest.*reads,input()or a function parameter. - Python:
RedirectResponse, theHTTPFoundfamily and aLocationheader (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. - Python skips a target that starts with
url_for()orreverse(), a fixed first path segment such as"/orders/" + slug(a slash and then a letter or digit), or"/?"or"/#". Inside anif, a name compared with==to a string literal, or tested withinagainst 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'surl_has_allowed_host_and_scheme(). Astartswith("/")ornetloccheck does not count, because//evil.examplepasses both. - TypeScript and JavaScript: any
.redirect(x)call whose first argument is not a string, template literal or number is reported, unlessxstarts with a fixed relative path orscheme://host/, or is built only from fixed text andprocess.envvalues. Request data does not have to be proven. Inside an Express, Koa, Next.js or similar handler, request data that can choose the host throughres.redirect(),NextResponse.redirect(),res.location()or aLocationheader is reported too, template literals included. - Go (from the Go engine as SKY-G220): request data in the target of
http.Redirect, Gin and Echoc.Redirector Fiberc.Redirect().To(), unless it comes after a literal?or#, or the value was parsed withurl.Parseand its scheme and host were checked before the redirect. - Java and Kotlin: request data reaching
sendRedirect(),RedirectView, KtorrespondRedirect()or a Spring"redirect:" + valueview name, unless a fixed prefix pins the host. C#: request data inRedirect()and its variants orResponse.Redirect(), unless guarded byUrl.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.
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 forredirect(). - 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 namesAccept 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.