A handler redirects to a location taken from the request without a check
What it finds
call.respondRedirect(call.parameters["next"]!!) sends the user wherever the link says. A link to the trusted site that redirects to a look-alike login page is the classic phishing step (CWE-601). Redirect only to paths of the site, or to addresses from a list the server keeps.
Reported for a request value, as for request-path-in-file-access, given to Ktor's respondRedirect, a servlet response's sendRedirect, RedirectView, or returned in a "redirect:" view name of a Spring controller.
From the rule's source, request_flows.rs.
import io.ktor.server.application.ApplicationCallimport org.springframework.web.bind.annotation.RequestParam class Login { suspend fun done(call: ApplicationCall) { call.respondRedirect(call.parameters["next"]!!)tx0 reports: the redirect target comes from the request call.respondRedirect("/home") } fun back(@RequestParam next: String): String { return "redirect:$next"tx0 reports: the redirect target comes from the request (next) } fun home(@RequestParam next: String): String { if (!next.startsWith("/")) return "redirect:/" return "redirect:$next" } fun view(@RequestParam tab: String): String = "settings/$tab"} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:open-redirect" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:open-redirect] reason="..."tx0 explain tx0/kotlin:open-redirect shows the same in the terminal. Found a false positive? Report it.