Title: Silent Trimming of Passwords Longer Than 72 Characters · Issue #283 · bcrypt-ruby/bcrypt-ruby · GitHub
Open Graph Title: Silent Trimming of Passwords Longer Than 72 Characters · Issue #283 · bcrypt-ruby/bcrypt-ruby
X Title: Silent Trimming of Passwords Longer Than 72 Characters · Issue #283 · bcrypt-ruby/bcrypt-ruby
Description: Description The bcrypt gem silently trims input strings longer than 72 characters during password hashing, which can lead to unexpected behavior. Specifically, when a string longer than 72 characters is provided, BCrypt::Password.create ...
Open Graph Description: Description The bcrypt gem silently trims input strings longer than 72 characters during password hashing, which can lead to unexpected behavior. Specifically, when a string longer than 72 characte...
X Description: Description The bcrypt gem silently trims input strings longer than 72 characters during password hashing, which can lead to unexpected behavior. Specifically, when a string longer than 72 characte...
Opengraph URL: https://github.com/bcrypt-ruby/bcrypt-ruby/issues/283
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Silent Trimming of Passwords Longer Than 72 Characters","articleBody":"## Description\n\nThe `bcrypt` gem silently trims input strings longer than **72** characters during password hashing, which can lead to unexpected behavior.\nSpecifically, when a string longer than **72** characters is provided, **BCrypt::Password.create** truncates the input to **72** characters without warning, allowing different inputs to produce the same hash. This can potentially enable password verification bypasses if an attacker uses a different string that matches the first **72** characters of the original input. (similar behavior has been posted by **OKTA**: https://trust.okta.com/security-advisories/okta-ad-ldap-delegated-authentication-username/ )\n\n## Steps to Reproduce \n1. Install the bcrypt gem (gem install bcrypt).\n2. Run the following Ruby script:\n```\nrequire 'bcrypt'\n\ncost = 12\nuserid = \"b91fa9b4-69f1-4779-8d45-73f8653057f3\" # 36 characters\nusername = \"my.very.long.username.with.more.characters@kondukto.io\" # 47 characters\npassword = \"randomStrongPassword\" # 20 characters\n\ninput = userid + username + password # Total: 103 characters\n\nbegin\n my_password = BCrypt::Password.create(input, cost: cost)\n puts \"Hashed password: #{my_password}\"\n\n # Validate the correct password\n is_valid = BCrypt::Password.new(my_password) == input\n puts \"Correct password validation: #{is_valid ? 'Success' : 'Failure'}\"\n\n # Validate with a different password\n wrong_password = \"AAAAAAAAAAAAAAAAAAAA\"\n bypass_input = userid + username + wrong_password # Also 103 characters\n is_valid = BCrypt::Password.new(my_password) == bypass_input\n puts \"Bypass password validation: #{is_valid ? 'Success' : 'Failure'}\"\nrescue BCrypt::Errors::InvalidCost, BCrypt::Errors::InvalidSalt =\u003e e\n puts \"Error creating password: #{e.message}\"\nend\n```\n3. Observe the output:\n```\n└\u003e ruby main.rb\nHashed password 1: $2a$12$nefsa21AluV1BF2EXx6Y4.u6ZV4KT3c1ZWXLIOpWV9KZZ2Y1lGQmO\nPassword validation: Success\nPassword validation: Success\n```\n## Expected Behavior\n- The bcrypt gem should either:\n - Raise an error when an input string exceeds 72 characters, indicating that the input is too long. \n - Explicitly document the 72-character limit and warn about truncation in the gem's documentation.\n- The validation of bypass_input (which differs from input after the first 72 characters) should return Failure, as it is a different string.\n\n## Actual Behavior\n- The bcrypt gem silently trims the input string to 72 characters.\n- Both input (103 characters) and bypass_input (103 characters, differing after 72 characters) validate successfully against the same hash, indicating that only the first 72 characters are considered.\n- No warning or error is raised about the truncation.\n\n## Suggested Fix\n- Add a check in BCrypt::Password.create to raise an error (e.g., **BCrypt::Errors::InputTooLong**) if the input exceeds 72 characters. _(this is how other programming languages handles it)_\n- Alternatively, log a warning when truncation occurs to alert developers.\n- Update the gem's documentation to clearly state the 72-character limit and the truncation behavior\n\n## Environment\n- Ruby version: ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux-gnu]\n- bcrypt version: 3.1.13\n- Operating System: Ubuntu 24.04.2 LTS \n\n## References\n- https://www.usenix.org/legacy/events/usenix99/provos/provos.pdf\n- https://en.wikipedia.org/wiki/Bcrypt\n- https://kondukto.io/blog/okta-vulnerability-bcrypt-auth","author":{"url":"https://github.com/ckalpakoglu","@type":"Person","name":"ckalpakoglu"},"datePublished":"2025-04-29T08:14:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/283/bcrypt-ruby/issues/283"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:71f516a8-26e8-7933-0c8c-720e8bb4a5f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FD8:127F38:B07B4B:DE8643:69759094 |
| html-safe-nonce | 1b13da4b0c6f7543027eb9b07dfe0071ff0d55431825b9272287fd57aa6ea01f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkQ4OjEyN0YzODpCMDdCNEI6REU4NjQzOjY5NzU5MDk0IiwidmlzaXRvcl9pZCI6IjU1Mjk4NzIzMzY0MTgwODI5NjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f3613b43c986673df12ad265bede62dc293a0e9f389e59fb5edcd273397d243f |
| hovercard-subject-tag | issue:3027463962 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/bcrypt-ruby/bcrypt-ruby/283/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e44647d49e7383f892d21a8e037f4f44c135cf30225808f91889d8ee42ad6c6c/bcrypt-ruby/bcrypt-ruby/issues/283 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e44647d49e7383f892d21a8e037f4f44c135cf30225808f91889d8ee42ad6c6c/bcrypt-ruby/bcrypt-ruby/issues/283 |
| og:image:alt | Description The bcrypt gem silently trims input strings longer than 72 characters during password hashing, which can lead to unexpected behavior. Specifically, when a string longer than 72 characte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ckalpakoglu |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| turbo-cache-control | no-preview |
| go-import | github.com/bcrypt-ruby/bcrypt-ruby git https://github.com/bcrypt-ruby/bcrypt-ruby.git |
| octolytics-dimension-user_id | 81594302 |
| octolytics-dimension-user_login | bcrypt-ruby |
| octolytics-dimension-repository_id | 15293 |
| octolytics-dimension-repository_nwo | bcrypt-ruby/bcrypt-ruby |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 15293 |
| octolytics-dimension-repository_network_root_nwo | bcrypt-ruby/bcrypt-ruby |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width