False negative in java/unvalidated-url-redirection for Spring MVC redirect view names

Aberta
#21,771 3 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
45/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
java, spring
Domínio
backend, security

Direção de pesquisa

Comece comparando a consulta estável java/unvalidated-url-redirection com a consulta experimental java/spring-unvalidated-url-redirection, concentrando-se nos nomes das views de redirect do Spring e nos fluxos mediados por helpers. Reproduza os padrões listados, incluindo as formas redirect:, ModelAndView e RedirectView, e verifique se os destinos controlados pelo usuário são reportados enquanto os redirects seguros permanecem inalterados.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

I ran into a false negative in the Java URL redirection queries for a common Spring MVC pattern.

java/unvalidated-url-redirection does not appear to cover redirects expressed through Spring view names like return "redirect:" + userControlledValue, especially when that construction is wrapped in a helper method.

I found this on a public CVE, CVE-2025-8813, in atjiu/pybbs.

Vulnerable code:

@GetMapping("changeLanguage")
public String changeLanguage(String lang, HttpSession session, HttpServletRequest request) {
    String referer = request.getHeader("referer");
    if ("zh".equals(lang)) {
        session.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, Locale.SIMPLIFIED_CHINESE);
    } else if ("en".equals(lang)) {
        session.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, Locale.US);
    }
    return StringUtils.isEmpty(referer) ? redirect("/") : redirect(referer);
}
protected String redirect(String path) {
    return "redirect:" + path;
}

This was fixed upstream by removing the user-controlled redirect target:
https://github.com/atjiu/pybbs/commit/edb14ff13e9e05394960ba46c3d31d844ff2deac

My understanding is that the stable query covers servlet-style redirect sinks such as sendRedirect(...) and Location headers, but not the Spring MVC redirect-by-view-name sink family. In this case the source is straightforward (request.getHeader("referer")) and the flow is short, so the gap seems to be sink coverage rather than source modeling.

This pattern is common in practice:

  • return "redirect:" + next
  • return new ModelAndView("redirect:" + next)
  • return new RedirectView(next)
  • helper wrappers such as redirect(next) in a base controller or utility class

That last form is especially common in real Spring code, so this is not just a one-off CVE shape. I would expect similar misses whenever a project centralizes redirect construction in a helper.

There is already an experimental query, java/spring-unvalidated-url-redirection, so this may just be a case where the relevant Spring sink modeling has not made it into the stable query set yet.

A reasonable fix might be to bring the Spring redirect sink coverage into the stable rule family, especially for:

  • "redirect:" + tainted
  • new ModelAndView("redirect:" + tainted)
  • new RedirectView(tainted)
  • helper-mediated variants that ultimately construct a Spring redirect view name
Linguagem predominante
CodeQL
Estrelas
10.1k
Forks
2.1k
Merge médio
2d 11h
PRs com merge (30d)
129

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/codeql

Todas as issues de github/codeql

Issues semelhantes

Mais issues de Backend & API Design

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.