Skip to main content

SKY-D252 · Security in code

Cookie sent without the Secure or HttpOnly flag

MediumCWE-614

Python, TypeScript/JavaScript and Go findings are MEDIUM, as in the catalog. Java findings are reported as HIGH.

Two cookie flags protect a login cookie. Secure tells the browser to send it only over HTTPS; HttpOnly hides it from page scripts. SKY-D252 reports cookies written with Secure turned off, and in TypeScript, JavaScript and Go also cookies that do not set both flags.

Languages
Python, TypeScript/JavaScript, Java, Go, Rust
Quality gate
counted toward the gate limits (full and diff scans). Java findings are HIGH, so they also count toward max_high.
Finding type
review
Catalog name
Insecure cookie
Go engine ID
SKY-G221, reported as SKY-D252
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A session cookie without Secure is sent in plain text whenever the user opens any http:// link to the site, so anyone on the same Wi-Fi can copy it and take over the session. Without HttpOnly, one cross-site scripting bug can read it with document.cookie.

What Skylos flags

app/auth.py · PythonReported on line 12
from flask import Flask, make_response, request from app.sessions import create_session app = Flask(__name__)  @app.post("/login")def login():    session_id = create_session(request.form["email"], request.form["password"])    response = make_response({"ok": True})    response.set_cookie("sid", session_id, httponly=True, secure=False)    return response

What Skylos leaves alone

app/auth.py · Python
import secrets from flask import Flask, make_response app = Flask(__name__)  @app.get("/form")def show_form():    token = secrets.token_urlsafe(32)    response = make_response({"csrf": token})    response.set_cookie("csrf_token", token, secure=True, httponly=False)    return response

Why Skylos leaves it alone

This CSRF token cookie is meant to be read by the page's own script, so httponly=False is deliberate, and secure=True keeps it on HTTPS. In Python the rule reports only a literal secure=False.

More languages

TypeScript

Flagged

src/routes/login.ts · TypeScriptReported on line 8
import express from "express";import { createSession } from "../sessions"; const router = express.Router(); router.post("/login", async (req, res) => {  const sessionId = await createSession(req.body.email, req.body.password);  res.cookie("sid", sessionId, { httpOnly: true, sameSite: "lax" });  res.json({ ok: true });}); export default router;

Not flagged

src/routes/login.ts · TypeScript
import express from "express";import { createSession } from "../sessions"; const router = express.Router(); router.post("/login", async (req, res) => {  const sessionId = await createSession(req.body.email, req.body.password);  const options = { httpOnly: true, secure: true, sameSite: "lax" as const };  res.cookie("sid", sessionId, options);  res.json({ ok: true });}); export default router;

Why Skylos leaves it alone

The options live in a variable, but Skylos follows it inside the handler and sees httpOnly: true and secure: true, the only combination it accepts for TypeScript and JavaScript.

Java

Flagged

src/main/java/com/example/LoginController.java · JavaReported on line 11
package com.example; import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletResponse; public class LoginController {    void remember(HttpServletResponse response, String sessionId) {        Cookie cookie = new Cookie("SESSION", sessionId);        cookie.setHttpOnly(true);        cookie.setSecure(false);        response.addCookie(cookie);    }}

Not flagged

src/main/java/com/example/ThemeController.java · Java
package com.example; import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletResponse; public class ThemeController {    void saveTheme(HttpServletResponse response, String theme) {        Cookie cookie = new Cookie("theme", theme);        cookie.setHttpOnly(false);        cookie.setSecure(true);        response.addCookie(cookie);    }}

Why Skylos leaves it alone

A theme cookie that page scripts read needs HttpOnly off, and it holds nothing secret. The Java check reports only cookies whose setSecure() call says false.

Go

Flagged

session.go · GoReported on line 6
package app import "net/http" func setSession(w http.ResponseWriter, sessionID string) {	http.SetCookie(w, &http.Cookie{		Name:     "sid",		Value:    sessionID,		Path:     "/",		HttpOnly: true,	})}

Not flagged

session.go · Go
package app import "net/http" func setSession(w http.ResponseWriter, sessionID string) {	http.SetCookie(w, &http.Cookie{		Name:     "sid",		Value:    sessionID,		Path:     "/",		HttpOnly: true,		Secure:   true,		SameSite: http.SameSiteLaxMode,	})}

Why Skylos leaves it alone

Both flags are written as true in the http.Cookie literal, which is what the Go check requires.

Rust

Flagged

src/session.rs · RustReported on line 3
use cookie::{Cookie, CookieJar};pub fn issue(jar: &mut CookieJar, token: String) {    jar.add(Cookie::new("session_id", token));}

Not flagged

src/session.rs · Rust
use cookie::{Cookie, CookieJar};pub fn issue(jar: &mut CookieJar, token: String) {    jar.add(Cookie::build(("session_id", token)).secure(true).build());}

Why Skylos leaves it alone

The session cookie requires HTTPS.

How Skylos decides

  1. In Rust, checks the Secure flag when a recognized cookie jar receives a cookie with a session or token name such as session_id or access_token. It follows cookie builders and set_secure on local bindings. It also checks directly returned axum-extra jars and cookies on Actix response builders finalized in the same call chain. Removal cookies, preference cookies and unknown flags stay quiet.
  2. Runs with --danger. Each language has its own check.
  3. Python: finds .set_cookie() and .set_signed_cookie() calls with at least a name and a value (Flask, Werkzeug, Django and Starlette share this signature). Reports MEDIUM only when secure is the literal False, by keyword or as the seventh positional argument. A missing, True or computed flag is not reported, nor is httponly=False on its own. Test modules are skipped.
  4. TypeScript and JavaScript: finds .cookie(name, value, options) calls on an HTTP response object, such as the res of an Express route. Options held in a variable in the same function are followed. Reports MEDIUM unless both httpOnly and secure are known to be true, so a call with no options, or with options it cannot follow, is reported. express-session and cookie-session middleware is reported when the session cookie's secure is missing or false (both default to false) or httpOnly is false; 'auto' or a computed value counts as set, and a call inside a development or test branch is skipped.
  5. Java: follows a Cookie made with new Cookie(...). When setSecure(...) receives a value known to be false (a literal or a constant) and the cookie is then passed to addCookie(), it reports HIGH. setHttpOnly is not checked.
  6. Go: the Go engine reports a net/http Cookie{...} literal when either HttpOnly or Secure is absent or proven false, including bounded boolean expressions and immutable constant aliases. A present flag whose runtime value is unknown is not judged. It reports SKY-G221, shown as SKY-D252.

How to fix it

Set secure=True and httponly=True on every session or login cookie, and add samesite="Lax" (or "Strict") so other sites cannot make the browser send it. In local development over plain HTTP, turn Secure off through configuration, not in the code that ships.

app/auth.py · Python · the fix, against the flagged file
from flask import Flask, make_response, request from app.sessions import create_session app = Flask(__name__)  @app.post("/login")def login():    session_id = create_session(request.form["email"], request.form["password"])    response = make_response({"ok": True})Removed:     response.set_cookie("sid", session_id, httponly=True, secure=False)Added:     response.set_cookie(Added:         "sid", session_id, httponly=True, secure=True, samesite="Lax"Added:     )    return response

When it can be wrong

  • TypeScript, JavaScript and Go also report harmless cookies that lack HttpOnly on purpose, such as a CSRF token or a UI preference the page script reads.
  • TypeScript and JavaScript: safe options kept in a module-level constant (const sessionCookie = { httpOnly: true, secure: true } outside the handler) are not followed, so the call is reported with both flags "unknown".
  • Missed: in Python, a cookie with secure left out (Flask then sends it without Secure unless configured) and framework settings such as SESSION_COOKIE_SECURE = False. In Java, cookies that never call setSecure() at all.

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 cookie may travel over plain HTTP.

    Python
    response.set_cookie("dev_sid", sid, secure=False)  # skylos: ignore[SKY-D252] dev only
  • [tool.skylos] ignore = ["SKY-D252"] 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.