Repository navigation
Description
Hardcoded Session Secret Enables User Impersonation
Hello, MapKnitter maintainers,
The repository's tracked Docker Compose configuration runs Rails in production without setting SECRET_KEY_BASE. Rails therefore falls back to the public hardcoded value below. Anyone who can reach an instance using this configuration can forge a session cookie for a known user ID, including an administrator or moderator.
Evidence
Although there are comments, the implementation is not "fail-close," so security risks still exist.
config/initializers/secret_token.rb:7 sets the cookie secret to:
Mapknitter::Application.config.secret_key_base = 'asdfjdasgaisaolghrwiohrkahguilboiwelkxwbranjkl'docker-compose.yml:13 defaults to the production image and docker-compose.yml:18-19 loads mapknitter.env. That committed environment file sets RAILS_ENV=production but does not define SECRET_KEY_BASE. config/secrets.yml:21-22 reads the production key from that environment variable. In Rails 5.2.8, SECRET_KEY_BASE takes precedence when present; otherwise Rails.application.secrets falls back to config.secret_key_base, which this initializer sets (Rails secrets fallback, Rails key selection). There is no production startup check that rejects the fallback.
config/initializers/session_store.rb:3 configures the encrypted _mapknitter_session cookie. ApplicationController#current_user trusts session[:user_id] and loads that database user. SpamController grants moderation actions based on the loaded user's admin or moderator role.
The Cloud Build deployment copies a separate app.yaml from a private GCS bucket before deploying (cloudbuild.yaml:10-13). This report concerns the tracked Docker Compose configuration and does not claim that the hosted App Engine instance uses the same key.
Proof of concept
On a controlled local copy using the tracked Compose configuration, replace 1 with an existing user's ID. This uses the app's Rails cookie jar to create the forged cookie:
docker compose exec -e TARGET_ID=1 web bundle exec rails runner -e production 'req = ActionDispatch::Request.new(Rack::MockRequest.env_for("/").merge(Rails.application.env_config)); jar = ActionDispatch::Cookies::CookieJar.build(req, {}); jar.signed_or_encrypted["_mapknitter_session"] = {"user_id" => Integer(ENV.fetch("TARGET_ID"))}; headers = {}; jar.write(headers); puts headers["Set-Cookie"]'Send the emitted cookie to the local instance:
curl -i -H 'Cookie: _mapknitter_session=<cookie-value>' http://localhost:3000/profileThe request is handled as the selected user. Using an administrator or moderator ID also satisfies the role check shown above.
Impact
An unauthenticated remote attacker can impersonate an existing account on a reachable instance using the tracked Compose configuration. Impersonating an administrator or moderator enables privileged moderation actions. The attacker must know an existing user's numeric ID.
Remediation
Remove the hardcoded initializer value. Require a unique, randomly generated SECRET_KEY_BASE in production and fail startup when it is missing. Rotate any key used by an affected deployment to invalidate forged and existing session cookies.
Related works
Hardcoded authentication-secret positives
- OpenProject, CVE-2026-46386 — a Docker image shipped a default Rails secret; a separate Marshal deserialization path enabled pre-authentication RCE.
- Autolab, CVE-2023-28641 — the recommended Docker Compose production setup could fall back to a shared hardcoded key, enabling session forgery and admin impersonation.
- Spree, CVE-2008-7311 — a hardcoded session-cookie key weakened cookie integrity protection.
Recent authentication edge cases
- ruby-jwt, CVE-2026-45363 — accepting an empty HMAC key allowed forged HS256 tokens; this is not a hardcoded-secret finding.
- rack-session, CVE-2026-39324 — a cookie decryption-failure fallback accepted attacker-controlled session data; Rails'
CookieStoreuses a separate implementation.
This report is part of my ongoing research. If you have any questions, please feel free to mention me here. I’d be glad to make this small contribution to improving MapKnitter’s security.
Activity
Anurag-S1ngh commentedon Oct 24, 2026
Hi, I'd like to take this issue. Could you assign it to me?
28Hus commentedon Oct 24, 2026
Thanks for offering to take this on! I have opened PR #1895 with a minimal fix for the production secret fallback. No need to assign the issue to you; I really appreciate your willingness to help, and feedback on the PR would be very welcome.