From 4dc605bece7fa2f9c3cf0785063539c0b54ea52d Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Sat, 29 Aug 2026 21:53:41 +0200 Subject: [PATCH] Reject unsupported salt costs --- lib/bcrypt/engine.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bcrypt/engine.rb b/lib/bcrypt/engine.rb index 1a253b3..eb45c68 100644 --- a/lib/bcrypt/engine.rb +++ b/lib/bcrypt/engine.rb @@ -80,7 +80,9 @@ def self.hash_secret(secret, salt, _ = nil) # Generates a random salt with a given computational cost. def self.generate_salt(cost = self.cost) cost = cost.to_i - if cost > 0 + if cost > MAX_COST + raise Errors::InvalidCost.new("cost must be <= #{MAX_COST}") + elsif cost > 0 if cost < MIN_COST cost = MIN_COST end