By NHI Mgmt Group Editorial TeamDomain: Cyber SecuritySource: SemgrepPublished July 31, 2026

TL;DR: Flask code that sets cookies without explicit Secure, HttpOnly, and SameSite flags was found by Semgrep, then the pattern was measured across 715 Flask apps on GitHub and 18 repositories with 66 instances were identified. The issue is not exotic exploitation, but avoidable session handling that leaves cookies more exposed to XSS and CSRF than most teams intend.


At a glance

What this is: This is a Semgrep check for Flask applications that flags cookie-setting calls missing explicit Secure, HttpOnly, or SameSite attributes.

Why it matters: It matters because cookie attribute hygiene is a basic web identity control, and omissions can weaken session protection even when the rest of the application appears correctly configured.

By the numbers:

👉 Read Semgrep's analysis of Flask cookie security flags and missing session protections


Context

Flask cookie handling is a small control with outsized identity implications because session cookies often become the front door to authenticated user state. When Secure, HttpOnly, and SameSite are left implicit, teams rely on defaults and assumptions rather than making the browser’s behaviour explicit, which is exactly where session exposure tends to creep in.

This is not an NHI or agentic AI story, but it still sits inside identity governance because browser session cookies are a core human identity mechanism. The governance lesson is that access protections are only as strong as the code that sets and transmits the credential-bearing cookie, not just the authentication flow that issued it.


Key questions

Q: How should teams implement secure cookie policy in Flask applications?

A: Set a secure default for every cookie that carries authenticated state, and make Secure, HttpOnly, and SameSite explicit in code. Then back that baseline with automated checks in CI so missing attributes are blocked before release. The key is consistency: a secure session model fails when only some routes or teams apply the rule.

Q: Why do missing cookie flags create identity risk in web apps?

A: Because cookies often represent the browser-side proof of an authenticated session. If scripts can read them, attackers can steal them through XSS. If browsers send them cross-site too freely, CSRF becomes easier. Missing flags therefore weaken the control over who can access or replay the session token.

Q: What do security teams get wrong about cookie hardening?

A: They often treat cookie flags as optional polish rather than part of the authentication boundary. That mindset leads to uneven settings across endpoints, especially in large Flask codebases. The practical failure is not just one unsafe cookie, but a policy that varies depending on which developer wrote the route.

Q: How can organisations tell whether cookie policy is actually working?

A: Look for every session-bearing cookie to have an explicit security declaration in code, and verify that CI blocks partial configurations. If exception cases exist, they should be rare, documented, and time-bound. A healthy programme can show both technical enforcement and a clear record of the few approved deviations.


Technical breakdown

Why cookie flags matter for session confidentiality

Cookies commonly carry session identifiers, so their security attributes determine who can read them and when browsers will send them. Secure limits transmission to HTTPS. HttpOnly prevents client-side scripts from reading the cookie, which reduces exposure if an XSS issue exists. SameSite changes whether browsers attach the cookie to cross-site requests, which directly affects CSRF risk. The important point is that these are not abstract hardening settings. They define how the browser handles an authentication-bearing token at runtime, and missing one control can leave the whole session model weaker than intended.

Practical implication: require explicit cookie attribute settings in every code path that creates session-bearing cookies.

How Flask set_cookie usage creates configuration drift

In Flask, set_cookie() makes it easy to define a cookie without forcing the developer to think about security attributes each time. That convenience can create inconsistent outcomes across endpoints, because one route may set secure=True while another omits httponly or samesite entirely. From a governance perspective, the risk is not a single bad cookie, but uneven policy enforcement across a codebase. Security checks that flag partial configurations help surface these inconsistencies before they become production defaults.

Practical implication: treat partial cookie flag coverage as policy drift and block merges until the application uses a consistent baseline.

Why explicit disablement is a useful control signal

The check described in the article allows explicit disabling of these flags when there is a reason to do so. That matters because security policy should distinguish between an intentional exception and an accidental omission. A codebase that can only express secure cookies by silence is harder to review and easier to misconfigure. Explicitly stating secure=False, httponly=False, or samesite=None gives reviewers and automation a clear signal that the decision was deliberate and hopefully documented.

Practical implication: require explicit security exceptions in code review so reviewers can distinguish design choices from missed controls.


NHI Mgmt Group analysis

Explicit cookie attributes are a session governance control, not a cosmetic hardening step. When teams leave Secure, HttpOnly, and SameSite implicit, they are outsourcing policy to framework defaults and browser behaviour. That weakens auditability and makes session handling harder to reason about during review, testing, and incident response. In identity programmes, the control point is the cookie issuance path itself, because that is where authenticated state becomes governable or exposed.

Session-cookie policy drift: inconsistent attribute handling across endpoints is the failure mode this check is designed to expose. A single codebase can mix safe and unsafe cookie settings depending on route, team, or release history. That pattern creates a fragmented identity boundary where users may be protected in one flow and exposed in another. Practitioners should see this as a policy enforcement problem, not just a code-quality issue.

Browser-managed session tokens deserve the same control discipline as any other credential. Cookies that carry authenticated state are effectively human identity secrets in transit, even if they are not usually treated that way operationally. This makes the topic relevant to IAM governance, application security, and privacy controls at once. Teams that already track credential handling in vaults and CI/CD pipelines should apply the same explicitness to browser-issued session cookies.

Semgrep-style static checks help convert insecure defaults into reviewable control gaps. Static analysis cannot prove a cookie is safe in every runtime condition, but it can reliably surface places where the application never made a security decision at all. That is the real value here: turning invisible assumptions into enforceable policy boundaries. Practitioners should use the finding as an input to secure coding standards and release gates, not as a one-off warning.

This pattern also shows why identity security extends into the application layer. Authentication may be handled elsewhere, but session persistence still depends on application code deciding how the browser should store and send the token. That makes cookie hygiene part of identity assurance, especially for web apps that depend on long-lived user sessions and cross-origin interactions. Security teams should therefore include cookie governance in application identity reviews.

What this signals

Cookie security checks are a useful reminder that identity governance often fails at implementation, not policy design. Teams can have strong authentication standards and still ship inconsistent browser-session handling across routes, frameworks, and product teams. The operational lesson is to treat cookie attributes as code-enforced policy, not developer memory.

Session-token handling should be reviewed alongside other credential-bearing surfaces. When browser cookies carry authenticated state, the control objective is the same as for secrets in vaults or tokens in pipelines. That makes application identity review a practical extension of IAM, especially where user sessions cross trust boundaries or rely on third-party content.

Credential exposure windows matter even for human sessions. If a session token is readable by scripts or transmitted too broadly, the attack window expands from the browser lifecycle into the application runtime. That is why browser-side controls belong in the same governance conversation as OWASP Non-Human Identity Top 10 and NIST Cybersecurity Framework 2.0 when teams are aligning identity and application controls.


For practitioners

  • Enforce explicit cookie flags in code review Require Secure, HttpOnly, and SameSite to be stated on every cookie-setting call unless a documented exception exists. Treat missing attributes as a merge-blocking defect, not a style preference.
  • Standardise a safe baseline for session cookies Define an application-wide default for authenticated cookies, then override only when a business case is documented. Make the baseline visible in secure coding standards so teams do not invent their own per-route patterns.
  • Add static checks to the release gate Run a Semgrep rule or equivalent policy check in CI so partial cookie configurations are caught before deployment. Escalate findings where different endpoints apply different cookie policies to the same user session.
  • Track deliberate exceptions separately Maintain a short exception register for cookies that cannot use one or more flags, including the reason and review date. That prevents intentional deviations from blending into accidental omissions.

Key takeaways

  • Flask cookie flags are an identity control because they govern how browser sessions are protected in transit and from script access.
  • The article’s data shows the issue is common enough to justify automation, with 18 affected repositories and 66 flagged instances across 715 Flask apps.
  • Teams should enforce explicit cookie policy in code review and CI so missing session protections become a blocked release, not a quiet default.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-03Cookie-bearing sessions parallel credential handling and explicit policy enforcement.
NIST CSF 2.0PR.AC-1Identity and access management controls support secure session handling.
NIST SP 800-53 Rev 5IA-5Authenticator management covers protections for session-bearing credentials.
CIS Controls v8CIS-6 , Access Control ManagementAccess control management extends to web session tokens and browser handling.

Apply explicit policy and automation to session-bearing credentials to prevent silent misconfiguration.


Key terms

  • HttpOnly Cookie: An HttpOnly cookie is a session cookie that JavaScript cannot read, which reduces the risk of theft through client-side script compromise. In BFF architectures, it is a common way to keep authentication material out of browser-accessible storage while still allowing the server to authorize requests.
  • SameSite Attribute: SameSite is a cookie attribute that controls whether browsers send a cookie with cross-site requests. It is commonly used to reduce CSRF exposure by limiting when a session token is attached to requests that originate from another site. The right setting depends on application behaviour and trust boundaries.
  • Secure Cookie Flag: The Secure flag instructs a browser to send a cookie only over HTTPS. That protects the cookie from being transmitted in cleartext over insecure channels, but it does not prevent script access or misuse by itself. Secure should be treated as a baseline transport control for any sensitive session cookie.
  • Persistent Cookie: A persistent cookie is a session cookie that remains valid after the browser closes until it expires or is explicitly removed. In remote access designs, it can improve usability, but it also increases the chance that a reused session becomes standing access if the organisation does not enforce compensating controls.

What's in the full article

Semgrep's full post covers the implementation detail this analysis intentionally leaves for the source:

  • The exact Semgrep rule logic for detecting missing secure, httponly, and samesite keyword arguments in Flask calls
  • The code examples showing acceptable explicit disablement and partial flag combinations
  • The repository sampling method behind the 715-app test set and the 66-instance finding
  • The practical check output you can use to reproduce the rule in your own codebase

👉 Semgrep's full post shows the rule logic, code examples, and repository findings behind the check

Deepen your knowledge

NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, IAM, and secrets management in the context of real control failures. It helps practitioners translate identity policy into enforcement across the systems their programmes depend on.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 1, 2026.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org