chulkilee
I need to call HTTP API verifying SSL or not. However, I found both httpc and hackney behave strange - ssl option stay across different functions.
See this code:
bad_url1 = "https://expired.badssl.com/"
bad_url2 = "https://wrong.host.badssl.com/"
# Testing httpc
# httpc by default does not check ssl
{:ok, _} = :httpc.request(:get, {to_charlist(bad_url1), []}, [], [])
# verify ssl
{:error, _} =
:httpc.request(
:get,
{to_charlist(bad_url1), []},
[ssl: [verify: :verify_peer, cacertfile: :certifi.cacertfile()]],
[]
)
# no verify again
{:ok, _} = :httpc.request(:get, {to_charlist(bad_url1), []}, [ssl: [verify: :verify_none]], [])
# verify ssl... DOES NOT work!
{:ok._()} =
:httpc.request(
:get,
{to_charlist(bad_url1), []},
[ssl: [verify: :verify_peer, cacertfile: :certifi.cacertfile()]],
[]
)
# Testing hackney
Application.ensure_all_started(:hackney)
{:error, _} = :hackney.request(:get, bad_url1, [], [], [])
{:error, _} = :hackney.request(:get, bad_url2, [], [], [])
# => :error, as expected
{:ok, 200, _headers, ref} = :hackney.request(:get, bad_url1, [], [], [:insecure])
# before reading the body, other requests without insecure fail
{:error, _} = :hackney.request(:get, bad_url1, [], [], [])
# once the body is read..
{:ok, _body} = :hackney.body(ref)
# => :ok, as expected
{:ok, 200, _headers, ref} = :hackney.request(:get, bad_url1, [], [], [])
{:ok, _body} = :hackney.body(ref)
# WHAT? as insecure is missing, this should fail due to ssl error!
At first I thought hackney keeps some options in pool (I created insecure option for a host is persistent in a pool · Issue #570 · benoitc/hackney · GitHub ) - but apparently httpc has the same issue.
Anyone had this issue?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #elixirconf-us
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #security
- #elixirconf-eu
- #api
- #forms
- #performance











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You might want to watch this:
The important point for your issue. Erlang will cache tls verifications.
chulkilee
Thanks!
I found hackney / httpc reuses http connection across different function calls, even they do not pass same references. This is bad behavior - as your SSL option might not be honored if other process calls the “bad cert” URL with verify_none. Wow.
I really hope mint get adopted. No state MUST be shared without explicit passing references!
voltone
In most applications, the decision whether a given TLS peer is trusted is determined by a global policy: either all is well (known issuer, not expired, correct hostname, etc.) or something is wrong, the decision does not depend on any kind of context. TLS session resumption and HTTP keep-alive are performance optimisations that work very well as long as this assumption holds.
In my talk I mentioned testing (automatic, or manual) as a scenario where these features can lead to unexpected results, and I pointed out how to disable them to get predictable results. But I do believe most users will want to leave them enabled in production.
In the scenario you describe, where some other process establishes unverified TLS connections, the real solution is of course to get that other process fixed.
If this is not possible, you’d have to take control of some of the lower layers yourself, to keep the secure and insecure parts of your application separate. At the HTTP layer you may be able to set up different connection pools (in
:httpc, define a custom ‘profile’ and use it instead of the default one; the profile is the ‘reference’ you mentioned, it’s just that there is an implicit default). At the TLS layer you’d have to disable connection reuse, or manage it yourself using theclient_reuse_sessions: :saveandclient_reuse_sessionoptions.Mint only helps in that it does not use a connection pool, but at the TLS layer it uses the standard
:sslapplication, with the same connection reuse behaviour as other HTTP clients.chulkilee
I think we’re on the same page in that 1) assumption of global policy and 2) global optimization based on the assumption leads to surprising behavior, and to make it work it needs “workaround” - not by using direct reference of connection but separating connection pool manually.
Also I understand that this is not http-level behavior/config, so http library may not need to handle this.
However, as far as a http client library supports SSL transport, it should handle this level issues “correctly”.
It is not just secure vs insecure - e.g. client cert auth will be broken if https connections are blindly shared.
Also it’s very disappointing that this assumption and behavior is not documented well in those libraries (implementing http pool connection and ssl support) - since this is important “side effect”.
For me, the best solution is to have deterministic pool name based on ssl option and pass it to “control” the behavior of http libraries (as discussed as a workaround)
Ideally, http client implementing pool connection with ssl transport layer should do that. It can use pool name with “default_#{inspect(ssloptions)}”
- and need to prune unused pool nicely.