Address potential weaknesses source of join-code generation - #952
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates JoinCodeGenerator to avoid potential join-code collisions caused by a shared Random instance being inherited across forked Puma workers, by switching generation to use OS-backed SecureRandom.
Changes:
- Replace the class-level
Randominstance withSecureRandom.random_numberfor consonant and digit generation. - Add a spec that asserts
SecureRandomis used for both code segments/components.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/join_code_generator.rb | Switches join-code generation from a shared Random instance to fork-safe SecureRandom. |
| spec/lib/join_code_generator_spec.rb | Adds a deterministic test that stubs SecureRandom.random_number and verifies the expected calls/output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test coverage92.18% line coverage reported by SimpleCov. |
raspberrypiherokubot
temporarily deployed
to
editor-api-p-issues-158-hsqyqo
August 6, 2026 11:26
Inactive
abcampo-iry
force-pushed
the
issues/1582
branch
from
August 6, 2026 11:38
6795650 to
8344e3c
Compare
zetter-rpf
approved these changes
Aug 6, 2026
Contributor
|
I like your theory! lets ship and see if it is fixed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
What's changed?
My guess for the Sentry error is that, JoinCodeGenerator created one Random.new instance when the application loaded.
Maybe Puma preloads the application and then forks its workers, so each worker inherited the same random-generator state. Those workers could therefore generate the same sequence of join codes, or there is a hash collision because of not being random although this is less likely.
The PR replaces that shared Random instance with SecureRandom, which obtains fork-safe randomness from the operating system. Each worker therefore generates an independent sequence.