Skip to content

Address potential weaknesses source of join-code generation - #952

Merged
abcampo-iry merged 1 commit into
mainfrom
issues/1582
Aug 6, 2026
Merged

Address potential weaknesses source of join-code generation#952
abcampo-iry merged 1 commit into
mainfrom
issues/1582

Conversation

@abcampo-iry

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings August 6, 2026 11:19
@cla-bot cla-bot Bot added the cla-signed label Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Random instance with SecureRandom.random_number for consonant and digit generation.
  • Add a spec that asserts SecureRandom is 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.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Test coverage

92.18% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/31098090733

@raspberrypiherokubot
raspberrypiherokubot temporarily deployed to editor-api-p-issues-158-hsqyqo August 6, 2026 11:26 Inactive
@zetter-rpf

Copy link
Copy Markdown
Contributor

I like your theory! lets ship and see if it is fixed

@abcampo-iry
abcampo-iry merged commit 5a0d65a into main Aug 6, 2026
5 checks passed
@abcampo-iry
abcampo-iry deleted the issues/1582 branch August 6, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants