Skip to content

Reporter token leaked via URL #28

Description

@simonforsberg

⚠️ Potential issue | 🟠 Major

Reporter token leaked via URL; also not URL-encoded on redirect.

Two concerns with propagating the token through query strings:

  1. Leakage. Placing the reporter token in the URL query string exposes it in browser history, server access logs, proxy logs, and Referer headers sent to any third-party resources embedded on the downstream page. Since this token is a bearer credential granting access to the ticket and its comments, this materially weakens its security. Consider using a short-lived signed cookie scoped to the ticket path instead, or rotating the token after use.
  2. Encoding. "?token=" + token concatenates user-supplied input into a redirect Location header without URL-encoding. In practice UUIDs are safe, but if the token format ever changes (or a malformed value is submitted), this could cause header/URL parsing issues. Use UriComponentsBuilder or URLEncoder.encode(token, StandardCharsets.UTF_8).
🔒 Minimal encoding fix (if the redirect target remains URL-based)
-        return "redirect:/view/id/" + ticketId + (token != null ? "?token=" + token : "");
+        String base = "redirect:/view/id/" + ticketId;
+        return token != null
+                ? base + "?token=" + URLEncoder.encode(token, StandardCharsets.UTF_8)
+                : base;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/example/alfs/controllers/TicketCommentController.java`
around lines 31 - 37, The redirect currently appends the reporter token into the
URL ("redirect:/view/id/" + ticketId + (token != null ? "?token=" + token : ""))
which leaks the bearer token and is not URL-encoded; instead, after calling
commentService.addComment(ticketId, dto, user, token) in TicketCommentController
(the method that calls getCurrentUserOrNull and commentService.addComment),
remove the token from the query string and set it as a short-lived, HttpOnly,
secure cookie scoped to the ticket path (e.g. /view/id/{ticketId}) or rotate the
token server-side and store the rotated value in a cookie; if you must keep a
URL redirect, URL-encode the token using UriComponentsBuilder or
URLEncoder.encode(token, StandardCharsets.UTF_8) before concatenation and prefer
rotating/invalidating the token immediately after use.

Originally posted by @coderabbitai[bot] in #26 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions