Skip to content

Make the session cookie unforgeable - #85

Merged
floatplane merged 1 commit into
floatplane:mainfrom
Allram:fix-session-auth
Jul 27, 2026
Merged

Make the session cookie unforgeable#85
floatplane merged 1 commit into
floatplane:mainfrom
Allram:fix-session-auth

Conversation

@Allram

@Allram Allram commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Fixes #59.

The session cookie was a constant — any client that set M2MSESSIONID=1 was treated as logged in, bypassing the password entirely, including for the OTA upload endpoints.

This implements the approach suggested in the issue discussion: the cookie value is now MD5(client IP + login password), recomputed and verified on every request via is_authenticated(). Properties:

  • The cookie can't be forged without knowing the password
  • It can't be replayed from a different IP address
  • Changing the login password invalidates all existing sessions
  • No server-side session storage needed

Also while touching these lines:

  • The cookie is now marked HttpOnly; SameSite=Strict
  • Logout sets Max-Age=0 so the browser actually drops the cookie

MD5Builder comes from the Arduino core on both ESP8266 and ESP32, so no new dependencies. Clients on changing IPs (DHCP lease change) will need to log in again, which seems like the right trade-off for a device like this.

Testing

  • pio test -e test-native passes; WEMOS_D1_Mini builds clean; src/ is clang-format-17 clean
  • Flashed and tested on a WEMOS D1 Mini connected to a live Mitsubishi unit

🤖 Generated with Claude Code

The session cookie was a constant: any client that set
M2MSESSIONID=1 was treated as logged in, bypassing the password
entirely — including for OTA firmware upload. The cookie value is now
MD5(client IP + login password), verified on every request, as
suggested in the issue discussion. Also marks the cookie
HttpOnly/SameSite=Strict and clears it properly on logout.

Fixes floatplane#59

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@floatplane floatplane left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for cleaning this up!

@floatplane
floatplane merged commit dde649c into floatplane:main Jul 27, 2026
14 checks passed
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.

is_authenticated is very dumb, doesn't even check the password

2 participants