Skip to content

fix(getting-started): use PersistedSecure and reject unknown session IDs in FirestoreSession - #1913

Merged
quartzmo merged 2 commits into
GoogleCloudPlatform:mainfrom
quartzmo:fix-firestore-session-fixation
Nov 25, 2026
Merged

quartzmo merged 2 commits into
GoogleCloudPlatform:mainfrom
quartzmo:fix-firestore-session-fixation

Conversation

@quartzmo

Copy link
Copy Markdown
Member
  • 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.

b/586646018

…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.
@quartzmo
quartzmo requested review from a team as code owners November 25, 2026 00:10
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 25, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@amanda-tarafa amanda-tarafa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with one comment.

ENV["RACK_ENV"] = "test"

require "digest/sha2"
require "minitest/autorun"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, thanks!

@quartzmo
quartzmo merged commit e0e4678 into GoogleCloudPlatform:main Nov 25, 2026
10 checks passed
@quartzmo
quartzmo deleted the fix-firestore-session-fixation branch November 25, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants