Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue RuntimeError when trying to use SecureRandom #1888

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Rescue RuntimeError when urandom is not available.
  • Loading branch information
stefansundin committed Feb 25, 2023
commit 279ebe6512f0a03f5951c705b009171a8aee67c5
4 changes: 2 additions & 2 deletions lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1848,8 +1848,8 @@ def force_encoding(*args)
begin
require 'securerandom'
set :session_secret, SecureRandom.hex(64)
rescue LoadError, NotImplementedError
# SecureRandom raises a NotImplementedError if no random device is available
rescue LoadError, NotImplementedError, RuntimeError
# SecureRandom raises a NotImplementedError if no random device is available, or RuntimeError if urandom is not available
dentarg marked this conversation as resolved.
Show resolved Hide resolved
set :session_secret, format('%064x', Kernel.rand((2**256) - 1))
end

Expand Down