lostisland / lostisland/faraday-net_http
Net::HTTP adapter trusts all system root CAs when a ca_file is specified
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 31
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
Problem
Faraday always trusts the OpenSSL system root CAs, even when a :ca_file or a :ca_path are specified, eg to implement CA pinning, or to reduce the number of trusted certificates.
Example
Faraday.new('https://www.google.com', ssl: { ca_file: '/not/used/by/google/ca.pem' }).get('/') # => #<Faraday::Response:0x007ffd580b19d8 ...
Expected behavior:
An error about server certificate certificate validation, because the website's certificate does not match the :ca_file
Root Cause:
Within the net_http adapter, ssl_cert_store will create a certificate store that includes the OpenSSL system root CAs if :cert_store is not specified:
https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb#L105
def ssl_cert_store(ssl)
return ssl[:cert_store] if ssl[:cert_store]
# Use the default cert store by default, i.e. system ca certs
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths
cert_store
end
I would think that Faraday should only set a default :cert_store if there is no :ca_file, no :ca_path, and no :cert_store specified.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read lib/faraday/adapter/net_http.rb at ssl_cert_store and trace how :ca_file, :ca_path, and :cert_store are selected. Done means a specified CA file or path is not accompanied by the system default roots, so the example fails certificate validation as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100