v0.14 is out: a mobile auth pack for Swift/iOS and Android, catching insecure token storage, cleartext traffic, and OAuth in embedded WebViews. Read more →
MEDIUM AI PREVALENCE: MEDIUM auth.betterauth.insecure-cookie

better-auth is configured to issue insecure session cookies.

Why AI tools produce this: AI coding tools produce this regularly, typically when prompted for a shortcut or a quick fix.

Why this matters

Under advanced, useSecureCookies: false forces the session cookie to be sent without the Secure flag (so it travels over plain HTTP and can be sniffed), and secure: false / httpOnly: false in defaultCookieAttributes (or a per-cookie attributes block) strips the protections that keep the cookie off HTTP and out of document.cookie.

Leave better-auth's secure defaults in place, or set useSecureCookies: true and keep secure/httpOnly at true. If you need insecure cookies for local HTTP dev, gate the value on process.env.NODE_ENV !== 'production' rather than hard-coding false.

VULNERABLE
vulnerable.ts
import { betterAuth } from "better-auth";

// Forcing useSecureCookies off ships the session cookie without the Secure
// flag, so it travels over plain HTTP and can be sniffed.
export const auth = betterAuth({
  advanced: {
    // ruleid: auth.betterauth.insecure-cookie
    useSecureCookies: false,
  },
});

// Turning off secure/httpOnly via the cookie attribute defaults is the same
// class of bug.
export const auth2 = betterAuth({
  advanced: {
    defaultCookieAttributes: {
      // ruleid: auth.betterauth.insecure-cookie
      secure: false,
      // ruleid: auth.betterauth.insecure-cookie
      httpOnly: false,
    },
  },
});
SAFE
safe.ts
import { betterAuth } from "better-auth";

// Secure cookies forced on (or simply left at better-auth's secure defaults).
export const auth = betterAuth({
  advanced: {
    useSecureCookies: true,
    defaultCookieAttributes: {
      secure: true,
      httpOnly: true,
      sameSite: "lax",
    },
  },
});

Suppressing this rule

If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.

// oauthlint-disable-next-line auth.betterauth.insecure-cookie -- <reason>

References

https://www.better-auth.com/docs/concepts/cookies ↗https://cwe.mitre.org/data/definitions/614.html ↗