{"action":"created","comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/59300005","id":59300005,"diff_hunk":"@@ -2,26 +2,28 @@\n \n module ActiveSupport\n   module SecurityUtils\n-    # Constant time string comparison.\n+    # Constant time string comparison, for fixed length strings.\n     #\n     # The values compared should be of fixed length, such as strings\n-    # that have already been processed by HMAC. This should not be used\n-    # on variable length plaintext strings because it could leak length info\n-    # via timing attacks.\n-    def secure_compare(a, b)\n-      return false unless a.bytesize == b.bytesize\n+    # that have already been processed by HMAC. Raises in case of length mismatch.\n+    def fixed_length_secure_compare(a, b)\n+      raise ArgumentError, \"string length mismatch.\" unless a.bytesize == b.bytesize\n \n       l = a.unpack \"C#{a.bytesize}\"\n \n       res = 0\n       b.each_byte { |byte| res |= byte ^ l.shift }\n       res == 0\n     end\n-    module_function :secure_compare\n+    module_function :fixed_length_secure_compare\n \n-    def variable_size_secure_compare(a, b) # :nodoc:\n-      secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))\n+    # Constant time string comparison, for variable length strings.\n+    #\n+    # The values are first processed by SHA256, so that we don't leak length info\n+    # via timing attacks.\n+    def secure_compare(a, b)\n+      fixed_length_secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))\n     end\n-    module_function :variable_size_secure_compare\n+    module_function :secure_compare","path":"activesupport/lib/active_support/security_utils.rb","position":36,"original_position":36,"commit_id":"1abcc86157303691395e561ff08e691e8ed38acc","original_commit_id":"1abcc86157303691395e561ff08e691e8ed38acc","user":{"login":"jeremy","id":199,"avatar_url":"https://avatars.githubusercontent.com/u/199?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremy","html_url":"https://github.com/jeremy","followers_url":"https://api.github.com/users/jeremy/followers","following_url":"https://api.github.com/users/jeremy/following{/other_user}","gists_url":"https://api.github.com/users/jeremy/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremy/subscriptions","organizations_url":"https://api.github.com/users/jeremy/orgs","repos_url":"https://api.github.com/users/jeremy/repos","events_url":"https://api.github.com/users/jeremy/events{/privacy}","received_events_url":"https://api.github.com/users/jeremy/received_events","type":"User","site_admin":false},"body":"Should we change other internal usage of secure_compare to use fixed_length_secure_compare now? In these cases we guarantee that the strings we're comparing are the same length, so raising an exception on mismatch is desirable.","created_at":"2016-04-11T23:36:49Z","updated_at":"2016-04-11T23:36:49Z","html_url":"https://github.com/rails/rails/pull/24510#discussion_r59300005","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/24510","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/59300005"},"html":{"href":"https://github.com/rails/rails/pull/24510#discussion_r59300005"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/24510"}}},"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/24510","id":66063289,"html_url":"https://github.com/rails/rails/pull/24510","diff_url":"https://github.com/rails/rails/pull/24510.diff","patch_url":"https://github.com/rails/rails/pull/24510.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/24510","number":24510,"state":"open","locked":false,"title":"Make variable_size_secure_compare public","user":{"login":"vipulnsward","id":567626,"avatar_url":"https://avatars.githubusercontent.com/u/567626?v=3","gravatar_id":"","url":"https://api.github.com/users/vipulnsward","html_url":"https://github.com/vipulnsward","followers_url":"https://api.github.com/users/vipulnsward/followers","following_url":"https://api.github.com/users/vipulnsward/following{/other_user}","gists_url":"https://api.github.com/users/vipulnsward/gists{/gist_id}","starred_url":"https://api.github.com/users/vipulnsward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vipulnsward/subscriptions","organizations_url":"https://api.github.com/users/vipulnsward/orgs","repos_url":"https://api.github.com/users/vipulnsward/repos","events_url":"https://api.github.com/users/vipulnsward/events{/privacy}","received_events_url":"https://api.github.com/users/vipulnsward/received_events","type":"User","site_admin":false},"body":"Ideally one would use `variable_size_secure_compare` over `secure_compare`, since its not leaking length information.\r\n\r\nSo make it public as well, as an option to `secure_compare` of variable length strings.\r\n\r\nr? @tenderlove \r\n","created_at":"2016-04-11T21:12:27Z","updated_at":"2016-04-11T23:36:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"194bf46186b6caa4b4dae90ae673794921d246b2","assignee":{"login":"tenderlove","id":3124,"avatar_url":"https://avatars.githubusercontent.com/u/3124?v=3","gravatar_id":"","url":"https://api.github.com/users/tenderlove","html_url":"https://github.com/tenderlove","followers_url":"https://api.github.com/users/tenderlove/followers","following_url":"https://api.github.com/users/tenderlove/following{/other_user}","gists_url":"https://api.github.com/users/tenderlove/gists{/gist_id}","starred_url":"https://api.github.com/users/tenderlove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tenderlove/subscriptions","organizations_url":"https://api.github.com/users/tenderlove/orgs","repos_url":"https://api.github.com/users/tenderlove/repos","events_url":"https://api.github.com/users/tenderlove/events{/privacy}","received_events_url":"https://api.github.com/users/tenderlove/received_events","type":"User","site_admin":true},"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/24510/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/24510/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/rails/issues/24510/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/1abcc86157303691395e561ff08e691e8ed38acc","head":{"label":"vipulnsward:make-variable_size_secure_compare-public","ref":"make-variable_size_secure_compare-public","sha":"1abcc86157303691395e561ff08e691e8ed38acc","user":{"login":"vipulnsward","id":567626,"avatar_url":"https://avatars.githubusercontent.com/u/567626?v=3","gravatar_id":"","url":"https://api.github.com/users/vipulnsward","html_url":"https://github.com/vipulnsward","followers_url":"https://api.github.com/users/vipulnsward/followers","following_url":"https://api.github.com/users/vipulnsward/following{/other_user}","gists_url":"https://api.github.com/users/vipulnsward/gists{/gist_id}","starred_url":"https://api.github.com/users/vipulnsward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vipulnsward/subscriptions","organizations_url":"https://api.github.com/users/vipulnsward/orgs","repos_url":"https://api.github.com/users/vipulnsward/repos","events_url":"https://api.github.com/users/vipulnsward/events{/privacy}","received_events_url":"https://api.github.com/users/vipulnsward/received_events","type":"User","site_admin":false},"repo":{"id":6652536,"name":"rails","full_name":"vipulnsward/rails","owner":{"login":"vipulnsward","id":567626,"avatar_url":"https://avatars.githubusercontent.com/u/567626?v=3","gravatar_id":"","url":"https://api.github.com/users/vipulnsward","html_url":"https://github.com/vipulnsward","followers_url":"https://api.github.com/users/vipulnsward/followers","following_url":"https://api.github.com/users/vipulnsward/following{/other_user}","gists_url":"https://api.github.com/users/vipulnsward/gists{/gist_id}","starred_url":"https://api.github.com/users/vipulnsward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vipulnsward/subscriptions","organizations_url":"https://api.github.com/users/vipulnsward/orgs","repos_url":"https://api.github.com/users/vipulnsward/repos","events_url":"https://api.github.com/users/vipulnsward/events{/privacy}","received_events_url":"https://api.github.com/users/vipulnsward/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vipulnsward/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/vipulnsward/rails","forks_url":"https://api.github.com/repos/vipulnsward/rails/forks","keys_url":"https://api.github.com/repos/vipulnsward/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vipulnsward/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vipulnsward/rails/teams","hooks_url":"https://api.github.com/repos/vipulnsward/rails/hooks","issue_events_url":"https://api.github.com/repos/vipulnsward/rails/issues/events{/number}","events_url":"https://api.github.com/repos/vipulnsward/rails/events","assignees_url":"https://api.github.com/repos/vipulnsward/rails/assignees{/user}","branches_url":"https://api.github.com/repos/vipulnsward/rails/branches{/branch}","tags_url":"https://api.github.com/repos/vipulnsward/rails/tags","blobs_url":"https://api.github.com/repos/vipulnsward/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vipulnsward/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vipulnsward/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/vipulnsward/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vipulnsward/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/vipulnsward/rails/languages","stargazers_url":"https://api.github.com/repos/vipulnsward/rails/stargazers","contributors_url":"https://api.github.com/repos/vipulnsward/rails/contributors","subscribers_url":"https://api.github.com/repos/vipulnsward/rails/subscribers","subscription_url":"https://api.github.com/repos/vipulnsward/rails/subscription","commits_url":"https://api.github.com/repos/vipulnsward/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/vipulnsward/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/vipulnsward/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/vipulnsward/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/vipulnsward/rails/contents/{+path}","compare_url":"https://api.github.com/repos/vipulnsward/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vipulnsward/rails/merges","archive_url":"https://api.github.com/repos/vipulnsward/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vipulnsward/rails/downloads","issues_url":"https://api.github.com/repos/vipulnsward/rails/issues{/number}","pulls_url":"https://api.github.com/repos/vipulnsward/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/vipulnsward/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/vipulnsward/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vipulnsward/rails/labels{/name}","releases_url":"https://api.github.com/repos/vipulnsward/rails/releases{/id}","deployments_url":"https://api.github.com/repos/vipulnsward/rails/deployments","created_at":"2012-11-12T11:42:33Z","updated_at":"2015-01-14T06:40:25Z","pushed_at":"2016-04-11T23:09:41Z","git_url":"git://github.com/vipulnsward/rails.git","ssh_url":"git@github.com:vipulnsward/rails.git","clone_url":"https://github.com/vipulnsward/rails.git","svn_url":"https://github.com/vipulnsward/rails","homepage":"http://rubyonrails.org","size":117407,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"20ffb63c2eb8ca65dc0d946deeadb8b4dda7ff3c","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","deployments_url":"https://api.github.com/repos/rails/rails/deployments","created_at":"2008-04-11T02:19:47Z","updated_at":"2016-04-11T23:32:43Z","pushed_at":"2016-04-11T23:09:44Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":331094,"stargazers_count":30578,"watchers_count":30578,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12424,"mirror_url":null,"open_issues_count":930,"forks":12424,"open_issues":930,"watchers":30578,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/24510"},"html":{"href":"https://github.com/rails/rails/pull/24510"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/24510"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/24510/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/24510/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/24510/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/1abcc86157303691395e561ff08e691e8ed38acc"}}}}