Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Cookies set by CasWAF lacked the SameSite attribute, causing browsers to apply inconsistent defaults and potentially exposing the application to CSRF attacks.

Changes

  • service/captcha.go: Updated casdoor_captcha_token cookie

    • Set SameSite: http.SameSiteLaxMode
    • Enabled HttpOnly: true
    • Set Secure: scheme == "https" (conditional on connection type)
  • service/oauth.go: Updated casdoor_access_token cookie

    • Set SameSite: http.SameSiteLaxMode
    • Enabled HttpOnly: true
    • Set Secure: scheme == "https" (conditional on connection type)
  • service/cookie_test.go: Added tests validating cookie security attributes for both HTTP and HTTPS contexts

Example

// Before
cookie := &http.Cookie{
    Name:  "casdoor_access_token",
    Value: token.AccessToken,
    Path:  "/",
}

// After
scheme := getScheme(r)
cookie := &http.Cookie{
    Name:     "casdoor_access_token",
    Value:    token.AccessToken,
    Path:     "/",
    HttpOnly: true,
    Secure:   scheme == "https",
    SameSite: http.SameSiteLaxMode,
}

The SameSite=Lax setting prevents CSRF attacks while preserving cookie functionality for OAuth callbacks and top-level navigation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Cookie with Missing, Inconsistent, or Conflicting Attributes</issue_title>
<issue_description>List of cookies with missing, inconsistent, or conflicting attributes:
https://ai-admin.casibase.com/

Cookie set with the following attributes:
Set-Cookie: casibase_session_id=6a409bcc77e742bf3def00e4cff5e59a; Path=/; HttpOnly

This cookie has the following issues:

  • Cookie without SameSite attribute.

When cookies lack the SameSite attribute, web browsers may apply different and sometimes unexpected defaults. It is therefore recommended to add a SameSite attribute with an appropriate value of either "Strict", "Lax", or "None".

At least one attribute of the cookie causes this cookie to be invalid or incompatible with other attributes of this cookie or the usage environment of this cookie. While this is not a vulnerability in itself, it may lead to unexpected behavior in the application, which could result in minor security issues.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nomeguy nomeguy marked this pull request as ready for review October 30, 2025 05:40
Copilot AI and others added 3 commits October 30, 2025 05:48
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing SameSite attribute in cookies Add SameSite attribute and security flags to authentication cookies Oct 30, 2025
Copilot AI requested a review from nomeguy October 30, 2025 05:56
Copilot finished work on behalf of nomeguy October 30, 2025 05:56
@nomeguy nomeguy closed this Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cookie with Missing, Inconsistent, or Conflicting Attributes

3 participants