Skip to main content

SKY-D254 · Security in code

Request data stored in the HTTP session

High

The HTTP session is data the server keeps for each logged-in user, and code usually trusts it more than the request. A "trust boundary violation" is putting data the client chose into that trusted place. SKY-D254 reports Java servlet and Spring code that stores request data in the session with getSession().setAttribute(...).

Languages
Java
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Catalog name
HTTP session trust boundary violation
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Other pages read the session later and assume the server put the value there. If a login form's hidden role field is copied into the session, a user can send role=admin once and every later admin check passes.

What Skylos flags

src/main/java/com/example/LoginServlet.java · JavaReported on line 13
package com.example; import java.io.IOException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; public class LoginServlet extends HttpServlet {    @Override    protected void doPost(HttpServletRequest request, HttpServletResponse response)            throws IOException {        String role = request.getParameter("role");        request.getSession().setAttribute("role", role);        response.sendRedirect("/dashboard");    }}

What Skylos leaves alone

src/main/java/com/example/LoginServlet.java · Java
package com.example; import java.io.IOException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; public class LoginServlet extends HttpServlet {    private final RoleStore roles = new RoleStore();     @Override    protected void doPost(HttpServletRequest request, HttpServletResponse response)            throws IOException {        String role = roles.roleFor(request.getRemoteUser());        request.getSession().setAttribute("role", role);        response.sendRedirect("/dashboard");    }}

Why Skylos leaves it alone

The role comes from the server's own store, looked up for the user the servlet container has already signed in. getRemoteUser() is not one of the request-input methods the rule follows, such as getParameter() or getHeader().

More languages

Java

Flagged

src/main/java/com/example/CartController.java · JavaReported on line 13
package com.example; import javax.servlet.http.HttpServletRequest;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class CartController {    @PostMapping("/cart/discount")    public String applyDiscount(@RequestParam String code,            HttpServletRequest request) {        request.getSession().setAttribute("discountCode", code);        return "ok";    }}

Not flagged

src/main/java/com/example/CartController.java · Java
package com.example; import javax.servlet.http.HttpServletRequest;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class CartController {    @PostMapping("/cart/discount")    public String applyDiscount(@RequestParam String code,            HttpServletRequest request) {        boolean welcome = "WELCOME10".equals(code);        request.getSession().setAttribute("discountPercent", welcome ? 10 : 0);        return "ok";    }}

Why Skylos leaves it alone

The request only chooses between two numbers the code itself defines, so the session holds 10 or 0, never the client's text. Skylos sees that both branches of the ? : are constants.

How Skylos decides

  1. Runs with --danger on Java files and follows values inside each method.
  2. Request data is a value from getParameter(), getHeader(), getCookies(), getQueryString(), getInputStream(), getPart() and similar methods on the request, or a Spring or JAX-RS handler parameter bound from the request (@RequestParam, @PathVariable, @RequestBody, @QueryParam and others). The value stays marked through assignments, string building and method calls.
  3. Reports HIGH when such a value is an argument of setAttribute() or putValue() called on an expression that contains a getSession() call, such as request.getSession().setAttribute(...).
  4. Constants, and values that only choose between constants, are not request data.

How to fix it

Store only values the server decided: look the role up from your own user store after authentication, and map client choices onto a fixed set of values before saving them. Treat anything the client sent as input to check, not as session state.

src/main/java/com/example/LoginServlet.java · Java · the fix, against the flagged file
package com.example; import java.io.IOException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; public class LoginServlet extends HttpServlet {Added:     private final RoleStore roles = new RoleStore();Added:      @Override    protected void doPost(HttpServletRequest request, HttpServletResponse response)            throws IOException {Removed:         String role = request.getParameter("role");Added:         String role = roles.roleFor(request.getRemoteUser());        request.getSession().setAttribute("role", role);        response.sendRedirect("/dashboard");    }}

When it can be wrong

  • Values computed from request data are still reported even when they are safe to keep, such as a discount percentage looked up by a coupon code, or a search term saved only to fill the search box again.
  • Missed: a session held in a variable (HttpSession session = request.getSession(); session.setAttribute(...)) and a Spring HttpSession handler parameter, because the call itself must contain getSession(). Kotlin and other languages are not checked.

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 value is safe to keep.

    Java
    request.getSession().setAttribute("search", q); // skylos: ignore[SKY-D254] refill only
  • [tool.skylos] ignore = ["SKY-D254"] turns the rule off for the whole project.

  • skylos baseline . and then --baseline accept the existing findings and report only new ones.

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