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: Semgrep analysed Flask cookie handling and found that missing Secure, HttpOnly, and SameSite flags remain a common session security gap in real code.
Why it matters: This matters because cookie flag hygiene directly affects session theft and cross-site abuse risk, and teams need to know when framework defaults are not enough.
Context
Cookie security is a session governance problem, not just a framework setting. When applications set cookies without explicit Secure, HttpOnly, and SameSite attributes, they leave browser-managed session data more exposed to script access, cross-site request abuse, and transport downgrade risk. The issue is especially relevant where application code creates identity-bearing session cookies but does not enforce a consistent security policy at issuance time.
For identity and access teams, the interesting part is that the control boundary sits in the application layer but the impact lands in session trust. Flask makes these flags easy to set, yet the article shows that omission still happens often enough to matter. That is a typical pattern in web estates: the capability exists, but explicit governance of cookie handling is incomplete.
Key questions
Q: How should teams handle cookies that do not explicitly set Secure, HttpOnly, and SameSite?
A: Treat missing cookie flags as a security decision, not a harmless omission. If a cookie carries session or identity state, require Secure, HttpOnly, and SameSite unless a specific workflow justifies an exception. The important control is explicitness, because the application is defining the browser trust boundary at issuance time.
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 are the signs that device security controls are being applied inconsistently?
A: Common warning signs include laptops left unlocked at desks, devices taken offsite without secure storage, and delayed operating system or software updates. In practice, these behaviours show that basic hygiene is not being followed, which increases the chance of theft, unauthorised access, and infection. If users frequently bypass these habits, the programme is not being embedded well.
Q: Should organisations prefer explicit cookie policy or rely on framework defaults?
A: Prefer explicit policy every time. Framework defaults can help with usability, but they do not guarantee that every session cookie is issued with the right browser constraints. When access-bearing cookies are involved, the safer pattern is to make the intended posture visible in code and test for it in review.
Technical breakdown
Why Secure, HttpOnly, and SameSite matter for session cookies
Secure instructs the browser to send a cookie only over HTTPS, which protects it from interception on insecure transport. HttpOnly blocks client-side scripts from reading the cookie, reducing the blast radius of XSS when an attacker can execute JavaScript in the browser. SameSite limits when cookies accompany cross-site requests, which is one of the key browser-side controls used to reduce CSRF exposure. These attributes are not interchangeable: they address different failure modes in the session lifecycle. In practice, a session cookie that omits one or more of them may still function, but it carries avoidable exposure that security teams often discover only after a review.
Practical implication: Treat cookie attribute enforcement as part of application identity control, not a cosmetic hardening step.
How framework defaults can create an explicitness gap
Frameworks reduce friction, but they also make unsafe omission easy when security properties are optional rather than mandatory. In Flask, set_cookie() accepts these attributes as keyword arguments, which means the burden falls on developers to specify the desired posture every time a cookie is issued. That creates an explicitness gap: the application may be technically correct, yet still fail to declare its trust boundary clearly. This is a governance problem because absence of an argument is still a decision, just an undocumented one. Static analysis is effective here because it can detect incomplete calls before deployment and prompt a design-level choice about each cookie’s intended exposure.
Practical implication: Use code scanning to catch cookies whose security posture is implicit instead of declared.
Why explicit disabling is different from accidental omission
The article notes that the check permits explicit disabling, which is an important distinction. There are legitimate cases where Secure, HttpOnly, or SameSite may be set to false or omitted because a cookie is not meant to carry sensitive session state or must support a specific workflow. That is not the same as forgetting to set them. Security policy works better when exceptions are intentional, reviewable, and visible in code. The real weakness is uncontrolled inconsistency, where developers inherit framework flexibility but do not express the security rationale. That is where session risk accumulates across large codebases.
Practical implication: Allow exceptions only when they are deliberate and reviewable in the code path that sets the cookie.
NHI Mgmt Group analysis
Cookie security is a session governance control, not a browser tuning preference. The article reinforces that Secure, HttpOnly, and SameSite each address a different exposure window in browser-managed session handling. When teams treat them as optional hints, they create a policy gap between authentication and session protection. Practitioners should treat cookie issuance as a governed control point, because the identity session is only as strong as the attributes attached to it.
Static analysis closes the only realistic control point for this class of defect. Once a cookie reaches production without explicit flags, the exposure is already embedded in runtime behaviour. This is why the named concept here is session explicitness gap: security intent exists in policy, but not in the code that actually issues the credential-bearing cookie. Practitioners should push enforcement earlier, where omission can be blocked rather than reviewed after the fact.
This finding also shows why application security and IAM cannot stay in separate silos. A session cookie is an access token in practical terms, even when the application team does not describe it that way. If issuance logic does not encode the right browser constraints, the downstream identity boundary weakens regardless of backend authentication strength. Practitioners should govern cookie-setting paths with the same seriousness they apply to other authentication and session controls.
Flask’s flexibility is useful, but flexibility without policy produces uneven security outcomes. The article’s measured prevalence suggests that this is not an edge case, it is a repeatable development pattern. That means the challenge is not awareness alone but policy consistency across repositories and teams. Practitioners should standardise the expected cookie posture and make deviations obvious in review.
The broader lesson is that explicitness beats assumption in web session security. Browser controls only protect what the application chooses to declare, and omission is rarely a safe default. For IAM and application security teams, this is a reminder that identity assurance can be undermined by small implementation gaps at the point of session creation. Practitioners should focus on declaration, not just capability.
What this signals
Session explicitness gap: the real control problem is not whether Flask supports secure cookie attributes, but whether teams make the security posture explicit at the point of cookie issuance. That distinction matters because omitted attributes become inherited risk across every browser session that relies on the cookie.
Application security teams should treat cookie-setting code as part of identity governance, especially where the cookie carries session authority. A small number of missing attributes can create broad exposure, but the fix is architectural discipline rather than a one-off patch.
The most useful outcome is standardisation: make Secure, HttpOnly, and SameSite the expected baseline for session cookies, then require an exception path when a workflow cannot support one of them.
For practitioners
- Enforce explicit cookie flags at issuance Require Secure, HttpOnly, and SameSite to be declared in every session cookie call unless a documented exception exists.
- Scan repositories for incomplete set_cookie() calls Use static analysis to find any Flask set_cookie() usage where one or more security attributes are missing, then route those findings to code review.
- Document approved cookie exceptions Maintain a short policy for when a cookie may intentionally disable Secure, HttpOnly, or SameSite, and require the rationale in code review.
- Align cookie policy with session risk Review cookies that carry identity or session state and apply the same governance discipline you use for other access-bearing credentials.
Key takeaways
- Missing cookie flags turn routine session handling into a security gap because browser-managed cookies need explicit controls to resist script access and cross-site abuse.
- Semgrep measured the pattern at scale across 715 Flask apps on GitHub and found 18 repositories with 66 instances, showing that the problem is common rather than theoretical.
- The right response is to make cookie posture explicit in code review and static analysis, with documented exceptions instead of accidental omission.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST CSF 2.0, CIS Controls v8 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V7 — Session Management | Cookie flags govern browser session handling and session protection. |
| V6 — Authentication | Session cookies carry authentication state and must be protected as such. | |
| Recommendation — Apply V7 to require explicit session cookie attributes and review any omitted controls. Use V6 to ensure authenticated sessions are protected by secure cookie handling. | ||
| NIST CSF 2.0 | PR.AA-05 — Access Permissions, Entitlements and Authorizations | Cookie-based sessions are access-bearing authorisations in web applications. |
| Recommendation — Map session cookie issuance to PR.AA-05 and enforce explicit authorisation boundaries. | ||
| CIS Controls v8 | CIS-5 — Account Management | Session cookies support user account access and should be governed consistently. |
| Recommendation — Use CIS-5 to standardise how account-access cookies are issued and controlled. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Cookie-based sessions behave like authenticators that need controlled handling. |
| Recommendation — Apply IA-5 to manage session-cookie lifecycle, issuance, and security requirements. | ||
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.
- 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.
- 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.
- Session Explicitness Gap: A control gap that appears when an application supports security attributes but developers omit them or set them inconsistently at cookie issuance time. The risk is not the lack of a framework feature, but the absence of an explicit security decision in code where access-bearing cookies are created.
Deepen your knowledge
NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, IAM, and secrets management in a practitioner-focused format. It is designed for security teams that need to connect access controls with real-world governance decisions across applications and identity programmes.
Published by the NHIMG editorial team on August 1, 2026.
Updated on October 13, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org