Repository navigation
fix(getting-started): use PersistedSecure and reject unknown session IDs in FirestoreSession - #1913
Conversation
…IDs in FirestoreSession
- Subclass Rack::Session::Abstract::PersistedSecure, validate SessionId values, and key Firestore documents by sid.private_id rather than raw cookie strings.
- Return [generate_sid, {}] in find_session when no Firestore document exists, overwrite session documents without merge: true, and honor options[:drop] in delete_session.
- Pass httponly: true, same_site: :lax, secure: production? when mounting Rack::Session::FirestoreSession in app.rb, and add hermetic Minitest unit tests.
There was a problem hiding this comment.
Code Review
This pull request enhances session security in the Ruby Firestore session example. It updates FirestoreSession to inherit from Rack::Session::Abstract::PersistedSecure instead of Abstract::Persisted, ensuring that session IDs are hashed before being stored in Firestore (using private_id). It also configures secure cookie options (httponly, same_site: :lax, and secure in production) and adds validation for session IDs to prevent session fixation and path traversal attacks. Additionally, a comprehensive test suite has been introduced to verify these security behaviors. There are no review comments, and I have no additional feedback to provide.
| ENV["RACK_ENV"] = "test" | ||
|
|
||
| require "digest/sha2" | ||
| require "minitest/autorun" |
There was a problem hiding this comment.
My bots caught this as a regression in nightly testing and it seems legit.
Adding test/app_test.rb enables getting-started/sessions in .toys/kokoro-ci.rb, and on non-presubmit runs test_minitest passes --junit --junit-filename=sponge_log.xml under bundler/setup. Since getting-started/sessions/Gemfile currently has gem "rspec_junit_formatter" instead of gem "minitest-junit", nightly Kokoro on ruby-oldest will fail with invalid option: --junit. Could we swap in gem "minitest-junit" in Gemfile?
… in sessions Gemfile
b/586646018