Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a3bf1a1
fix(http): credentialed callers never follow redirects; URL-credentia…
claude Nov 17, 2026
b5cb9e3
fix(arangodb): a 3xx from a POST is an error, not a decoded success
claude Nov 17, 2026
66b99f9
fix(arangodb): reject POST redirects and handle schema setup failures
coderabbitai[bot] Nov 17, 2026
7346652
fix(arangodb): reconcile remote redirect regression coverage
coderabbitai[bot] Nov 17, 2026
e97366e
test(httpc): cross-origin cases also change the host, not only the port
claude Nov 17, 2026
b53a3ac
fix(arangodb): schema setup keeps the HTTP status of each step
claude Nov 17, 2026
8b4d10e
Merge remote-tracking branch 'origin/main' into claude/clever-heisenb…
claude Nov 17, 2026
8c60abb
fix(arangodb): skip database creation when the target already exists
claude Nov 17, 2026
c3047c8
fix(reviewer): follow same-origin redirects, at most three
claude Nov 17, 2026
92a1fb4
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 17, 2026
6978a23
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 18, 2026
322b62d
fix(reviewer): bound the redirect chain and refuse userinfo redirects
claude Nov 18, 2026
d42b37a
fix(arangodb): probe the target database, verify setup, retry with ba…
claude Nov 18, 2026
4cbc9ac
fix(arangodb): a sync run with a failed upsert is not recorded as com…
claude Nov 18, 2026
2004b00
test(httpc): check each redirect probe sends its credentials first
claude Nov 18, 2026
b81d66a
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 18, 2026
2431a6a
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 18, 2026
d05df32
fix(shell): avoid SIGPIPE failures from grep -q in pipelines
coderabbitai[bot] Nov 18, 2026
f4f41ce
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 21, 2026
9df47ae
Merge remote-tracking branch 'origin/main' into claude/clever-heisenb…
claude Nov 23, 2026
f8332b4
fix(deps): port #1225, url 2.5.9 for RUSTSEC-2026-0592
claude Nov 24, 2026
c0d4e7d
fix(arangodb): read before create, retry setup off the server loop, s…
claude Nov 24, 2026
2e4706a
fix(arangodb): a collection of the wrong type, or a unique/sparse ind…
claude Nov 24, 2026
11a4222
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 24, 2026
58e48ea
Merge branch 'main' into claude/clever-heisenberg-q9qp32
hyperpolymath Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
571 changes: 422 additions & 149 deletions lib/data/arangodb.ex

Large diffs are not rendered by default.

77 changes: 70 additions & 7 deletions lib/hypatia/reviewer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,78 @@ defmodule Hypatia.Reviewer do
[]
end

case :httpc.request(:get, {String.to_charlist(url), headers}, [{:timeout, 15_000}], []) do
{:ok, {{_, 200, _}, _resp_headers, body}} ->
{:ok, to_string(body)}
get_same_origin(url, headers)
end

{:ok, {{_, status, _}, _, _}} ->
{:error, {:http_status, status}}
@max_redirects 3
@timeout_ms 15_000

# GET that follows a redirect only to the origin (scheme, host and port)
# of the first request, at most @max_redirects times. GitHub answers a
# request for a renamed repository with a 301 to
# https://api.github.com/repositories/<id>/..., so the review still runs,
# while the token never reaches another origin or a plain-HTTP downgrade.
# A Location carrying userinfo is refused too, so a redirect cannot add
# credentials of its own. :httpc's own redirect handling stays off (#1195).
# `timeout_ms` bounds the whole chain, not each hop: every request gets
# what is left of one monotonic deadline.
@doc false
def get_same_origin(url, headers, hops \\ @max_redirects, timeout_ms \\ @timeout_ms) do
follow_same_origin(url, headers, hops, System.monotonic_time(:millisecond) + timeout_ms)
end

{:error, reason} ->
{:error, {:http_error, reason}}
defp follow_same_origin(url, headers, hops, deadline) do
remaining = deadline - System.monotonic_time(:millisecond)

if remaining <= 0 do
{:error, {:http_error, :timeout}}
else
case :httpc.request(
:get,
{String.to_charlist(url), headers},
[{:timeout, remaining}, {:autoredirect, false}],
[]
Comment thread
hyperpolymath marked this conversation as resolved.
Resolved
) do
{:ok, {{_, 200, _}, _resp_headers, body}} ->
{:ok, to_string(body)}

{:ok, {{_, status, _}, resp_headers, _}} when status in [301, 302, 303, 307, 308] ->
with {:ok, target} <- redirect_target(url, resp_headers),
true <- same_origin?(url, target) and hops > 0 do
follow_same_origin(target, headers, hops - 1, deadline)
else
_ -> {:error, {:http_status, status}}
end

{:ok, {{_, status, _}, _, _}} ->
{:error, {:http_status, status}}

{:error, reason} ->
{:error, {:http_error, reason}}
end
end
end

defp redirect_target(url, resp_headers) do
with {_, location} <- List.keyfind(resp_headers, ~c"location", 0),
location = to_string(location),
nil <- URI.parse(location).userinfo do
{:ok, url |> URI.merge(location) |> URI.to_string()}
else
_ -> :error
end
end

# Host names compare case-insensitively (ASCII), as DNS does.
defp same_origin?(from, to) do
origin(from) == origin(to)
end

defp origin(url) do
uri = URI.parse(url)
{downcase(uri.scheme), downcase(uri.host), uri.port}
end

defp downcase(nil), do: nil
defp downcase(text), do: String.downcase(text, :ascii)
end
5 changes: 4 additions & 1 deletion mise.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[tools]
# Language runtimes
# Match the OTP 27.3.4.19 / Elixir 1.19.4 lanes in .github/workflows/ci.yml and tests.yml.
erlang = "27.3.4.19" # >= 27.3.4.13: :httpc drops authorization on cross-origin redirect
# OTP 27.3.4.19 drops header and URL credentials when a redirect changes host or port.
# Scheme alone is not checked: same-host, same-port HTTPS-to-HTTP redirects are not protected.
# Keep explicit redirect guards.
erlang = "27.3.4.19"
elixir = "1.19.4-otp-27"
node = "latest"
rust = "latest" # provides cargo, rustfmt and clippy
Expand Down
Loading
Loading