Files
codeql/ruby/ql/test/query-tests/security/cwe-295/Faraday.rb
Rasmus Wriedt Larsen 07d95918f2 Ruby: Add more RequestWithoutValidation.ql tests
Added:
- one where the value is not directly used when disabling certificate
  validation.
- one with argument passing, Faraday, where it is only the passing of
  `OpenSSL::SSL::VERIFY_NONE` that is recognized.
2022-08-19 15:42:50 +02:00

48 lines
1.2 KiB
Ruby

require "faraday"
# BAD
connection = Faraday.new("http://example.com", ssl: { verify: false })
response = connection.get("/")
# BAD
connection = Faraday.new("http://example.com", ssl: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
response = connection.get("/")
# GOOD
connection = Faraday.new("http://example.com")
response = connection.get("/")
# GOOD
response = Faraday.get("http://example.com")
# GOOD
connection = Faraday.new("http://example.com", ssl: { version: :TLSv1 })
response = connection.get("/")
# GOOD
connection = Faraday.new("http://example.com", ssl: { verify: true })
response = connection.get("/")
# GOOD
connection = Faraday.new("http://example.com", ssl: { verify_mode: OpenSSL::SSL::VERIFY_PEER })
response = connection.get("/")
# -- example of passing verify as argument --
def verify_as_arg(host, path, arg)
# BAD, due to the call below
connection = Faraday.new(host, ssl: { verify: arg })
response = connection.get(path)
end
verify_as_arg("http://example.com", "/", false)
def verify_mode_as_arg(host, path, arg)
# BAD, due to the call below
connection = Faraday.new(host, ssl: { verify_mode: arg })
response = connection.get(path)
end
verify_mode_as_arg("http://example.com", "/", OpenSSL::SSL::VERIFY_NONE)