SKY-D254 · Security in code
Request data stored in the HTTP session
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
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
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
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
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
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
- Runs with
--dangeron Java files and follows values inside each method. - 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,@QueryParamand others). The value stays marked through assignments, string building and method calls. - Reports HIGH when such a value is an argument of
setAttribute()orputValue()called on an expression that contains agetSession()call, such asrequest.getSession().setAttribute(...). - 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.
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 SpringHttpSessionhandler parameter, because the call itself must containgetSession(). 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--baselineaccept the existing findings and report only new ones.