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
Prev Previous commit
Update comment about SecureRandom
  • Loading branch information
dentarg authored Feb 26, 2023
commit ff4d68e62ce1f9b415481b93627759185509bb9e
3 changes: 2 additions & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,8 @@ def force_encoding(*args)
require 'securerandom'
set :session_secret, SecureRandom.hex(64)
rescue LoadError, NotImplementedError, RuntimeError
# SecureRandom raises a NotImplementedError if no random device is available, or RuntimeError if urandom is not available
# SecureRandom raises a NotImplementedError if no random device is available
# RuntimeError raised due to broken openssl backend: https://bugs.ruby-lang.org/issues/19230
set :session_secret, format('%064x', Kernel.rand((2**256) - 1))
end

Expand Down