Fix captcha validation

This commit is contained in:
syeopite 2023-07-26 16:40:32 -07:00
parent 0fd4beeac8
commit 9be4585d16
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
2 changed files with 5 additions and 3 deletions

View File

@ -198,6 +198,8 @@ module Invidious::Routes::Login
case captcha_type
when "image"
LOGGER.trace("Validating image Captcha")
answer = answer.lstrip('0')
answer = OpenSSL::HMAC.hexdigest(:sha256, HMAC_KEY, answer)
@ -207,7 +209,7 @@ module Invidious::Routes::Login
return error_template(400, "Erroneous CAPTCHA")
end
else # "text"
answer = Digest::MD5.hexdigest(answer)
answer = Digest::MD5.hexdigest(answer.downcase.strip)
if tokens.empty?
return error_template(400, "Erroneous CAPTCHA")

View File

@ -57,7 +57,7 @@ struct Invidious::User
return {
question: image,
tokens: {generate_response(answer, {":login"}, key, use_nonce: true)},
tokens: {generate_response(answer, {":captcha"}, key, use_nonce: true)},
}
end
@ -66,7 +66,7 @@ struct Invidious::User
response = JSON.parse(response)
tokens = response["a"].as_a.map do |answer|
generate_response(answer.as_s, {":login"}, key, use_nonce: true)
generate_response(answer.as_s, {":captcha"}, key, use_nonce: true)
end
return {