{"record":{"id":"3519b4c4a5edf142","repo":"jnunemaker/httparty","slug":"digest-auth-must-be-a-hash","errorCode":null,"errorMessage":":digest_auth must be a hash","messagePattern":":digest_auth must be a hash","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/httparty/request.rb","lineNumber":420,"sourceCode":"      options[:headers]['Cookie'] = cookies_hash.to_cookie_string\n    end\n\n    # Uses the HTTP Content-Type header to determine the format of the\n    # response It compares the MIME type returned to the types stored in the\n    # SupportedFormats hash\n    def format_from_mimetype(mimetype)\n      if mimetype && parser.respond_to?(:format_from_mimetype)\n        parser.format_from_mimetype(mimetype)\n      end\n    end\n\n    def validate\n      raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0\n      raise ArgumentError, 'only get, post, patch, put, delete, head, and options methods are supported' unless SupportedHTTPMethods.include?(http_method)\n      raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].respond_to?(:to_hash)\n      raise ArgumentError, 'only one authentication method, :basic_auth or :digest_auth may be used at a time' if options[:basic_auth] && options[:digest_auth]\n      raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].respond_to?(:to_hash)\n      raise ArgumentError, ':digest_auth must be a hash' if options[:digest_auth] && !options[:digest_auth].respond_to?(:to_hash)\n      raise ArgumentError, ':query must be hash if using HTTP Post' if post? && !options[:query].nil? && !options[:query].respond_to?(:to_hash)\n    end\n\n    def post?\n      Net::HTTP::Post == http_method\n    end\n\n    def set_basic_auth_from_uri\n      if path.userinfo\n        username, password = path.userinfo.split(':')\n        options[:basic_auth] = {username: username, password: password}\n        @credentials_sent = true\n      end\n    end\n\n    def decompress(body, encoding)\n      Decompressor.new(body, encoding).decompress\n    end","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/jnunemaker/httparty/blob/8f4a09e343b94de9f934f388028ca97620c9b378/lib/httparty/request.rb#L402-L438","documentation":"Request#validate raises ArgumentError ':digest_auth must be a hash' when options[:digest_auth] is truthy but does not respond to #to_hash. Like basic_auth, the digest option must be a Hash (with username/password); httparty then runs its Net digest auth middleware to answer the server's WWW-Authenticate challenge. Malformed values fail validation before any network round trip.","triggerScenarios":"`Foo.get(url, digest_auth: 'user:pass')`, `digest_auth: [user, pass]`, or passing the response's WWW-Authenticate header string instead of credentials.","commonSituations":"Migrating from gems that accept positional or string credentials, credentials loaded from ENV as 'user:pass', and copy-pasting a digest challenge header into the option.","solutions":["Pass a Hash: `digest_auth: { username: user, password: pass }`.","Split ENV-style creds: `digest_auth: Hash[%w[username password].zip(ENV['CREDS'].split(':'))]`.","Use the class-level `digest_auth user, pass` DSL for static credentials."],"exampleFix":"# before\nFoo.get(url, digest_auth: 'user:pass')   # String -> ArgumentError\n\n# after\nFoo.get(url, digest_auth: { username: 'user', password: 'pass' })","handlingStrategy":"validation","validationCode":"auth = { username: user, password: pass } unless auth.respond_to?(:to_hash)\nraise ArgumentError, ':digest_auth must be a hash' unless auth.respond_to?(:to_hash)\nFoo.get(url, digest_auth: auth)","typeGuard":"hash_like = ->(v) { v.respond_to?(:to_hash) }","tryCatchPattern":"begin\n  Foo.get(url, digest_auth: auth)\nrescue ArgumentError => e\n  raise unless e.message.include?('digest_auth')\n  Foo.get(url, digest_auth: { username: auth[:user], password: auth[:pass] })\nend","preventionTips":["Pass digest credentials as a Hash with username/password keys.","Split 'user:pass' ENV values at the config boundary.","Do not feed WWW-Authenticate challenge strings into digest_auth."],"tags":["ruby","httparty","validation","argument-error","authentication","digest-auth","request-options"],"backgroundTag":"invalid-argument-type","analyzedSha":"8f4a09e343b94de9f934f388028ca97620c9b378","analyzedAt":"2026-08-21T19:30:42.003Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}