Skip to content

Harden proxy-chain allowlist matching and single-logout sender check - #455

Closed
p-w wants to merge 5 commits into
apereo:masterfrom
p-w:security/hardening
Closed

p-w wants to merge 5 commits into
apereo:masterfrom
p-w:security/hardening

Conversation

@p-w

@p-w p-w commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Two small, config-dependent defense-in-depth hardenings. Neither is high severity, so a PR felt more appropriate than a private advisory.

1. Plain-string proxy-chain entries match beyond the URL authority (CAS_ProxyChain::matches)

String entries are compared with a bare case-insensitive prefix (strncasecmp). An entry without a path, e.g. https://proxy.example.com, which the docblock describes as a valid way to allow "a full domain" also accepts https://proxy.example.com.evil.net/cb and https://proxy.example.com@evil.net/cb (userinfo form; real host is evil.net).

Confirmed dynamically against a mock CAS returning <cas:proxy>: with chain entry https://proxy.example.com, a proxy URL of the ….evil.net/cb and …@evil.net/cb forms both authenticated as the victim before the change and are rejected after it.

Preconditions (hence Low–Moderate, config-dependent): the app uses allowProxyChain() with a string entry that has no path/trailing slash; the attacker runs a proxying service registered at the CAS server whose pgtUrl passes the CAS proxy policy; a victim authenticates to it.

Fix: a string entry without a path must end at a URL boundary (/, ?, #, or end of string). Entries that include a path keep prefix-matching as before. (Behaviour change: https://p.example.com no longer matches https://p.example.com:8443/….) 9 regression cases covered.

2. Single-logout sender check trusts an unverified PTR record (Client::handleLogoutRequests)

gethostbyaddr($_SERVER['REMOTE_ADDR']) is compared against the allowlist (default: the CAS hostname) without forward confirmation. On many providers the PTR record of a source IP is freely settable, so an attacker can set PTR = CAS hostname and pass the check, allowing forged SLO requests. Impact is limited (ending a specific session also needs the victim's service ticket), so Low / defense-in-depth (CWE-350).

Fix: forward-confirm with gethostbynamel($client) the resolved name must map back to REMOTE_ADDR, otherwise only the IP is compared.

The proxy-chain check was confirmed against a mock CAS; it has not been tested against a real Apereo CAS server with a proxy policy.

p-w added 2 commits November 6, 2026 09:18
A string entry such as https://app.example.com was compared with a bare
prefix match, so it also accepted proxy callback URLs like
https://app.example.com.evil.org/ or https://app.example.com@evil.org/.
Require that a string entry without a path ends at a URL boundary.
handleLogoutRequests() compared the PTR name of REMOTE_ADDR with the
allowed client list. The PTR record is controlled by the owner of the
source address, so fall back to the plain IP unless the name resolves
back to it.
@mergify

mergify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@p-w

p-w commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@prigaux

prigaux commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Hi,

p-w added 2 commits November 6, 2026 18:15
gethostbynamel() only returns IPv4 (A) records, so an IPv6 SingleLogout
client would never forward-confirm and would be rejected. Also resolve
AAAA records and compare the client address in packed form (inet_pton),
so equivalent IPv6 spellings match.
Covers that a plain string entry https://app.example.com does not match
https://app.example.com.evil.org/ or https://app.example.com@evil.org/,
while still matching the exact host and a path boundary.
@p-w

p-w commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both addressed:

  • e865d6f adds testUrlAuthorityBoundary in ProxyChainsTest.php, asserting that a plain https://app.example.com entry does not match https://app.example.com.evil.org/ or https://app.example.com@evil.org/, while still matching the exact host and a / path boundary.
  • 9a02282 fixes the IPv6 case you spotted: gethostbynamel() only returns A records, so an IPv6 SingleLogout client would never forward-confirm and would be rejected. The logout check now also resolves AAAA via dns_get_record() and compares the client address in packed form (inet_pton), so IPv6 clients confirm correctly and equivalent IPv6 spellings still match.

@prigaux

prigaux commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

It seems dns_get_record does not use system resolver. I suggest the following function (which handles both ipv4/ipv6):

function gethostbynamel46(string $host): array {
    $result = [];

    // forcing a socktype avoids duplicates (with different ai_socktype/ai_protocol combinaisons)
    foreach (socket_addrinfo_lookup($host, null, [ 'ai_socktype' => SOCK_STREAM ]) ?: [] as $info) {
        $addr = socket_addrinfo_explain($info);

        $ip = $addr['ai_addr']['sin_addr'] ?? ($addr['ai_addr']['sin6_addr'] ?? null);
        if ($ip) {
            $result[] = $ip;
        }
    }

    return $result;
}

dns_get_record() does not use the system resolver (it ignores /etc/hosts
and the configured resolver), so the AAAA lookup added for IPv6 could
disagree with how the host actually resolves the client name. Replace the
gethostbynamel() + dns_get_record(AAAA) pair with a _gethostbynamel46()
helper built on socket_addrinfo_lookup()/getaddrinfo (per maintainer
suggestion), which returns both IPv4 and IPv6 via the system resolver, and
fall back to gethostbynamel() when the sockets extension is unavailable.
@p-w

p-w commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, thanks. You're right that dns_get_record bypasses the system resolver. I've replaced the gethostbynamel() + dns_get_record(AAAA) pair with a _gethostbynamel46() helper built on socket_addrinfo_lookup() / getaddrinfo as you suggested, so both A and AAAA are resolved through the system resolver. I kept a fallback to gethostbynamel() for environments where the sockets extension is not available. Pushed in 5d11e2c; the proxy-chain / URL-authority tests pass.

prigaux pushed a commit that referenced this pull request Nov 20, 2026
A string entry such as https://app.example.com was compared with a bare
prefix match, so it also accepted proxy callback URLs like
https://app.example.com.evil.org/ or https://app.example.com@evil.org/.
Require that a string entry without a path ends at a URL boundary.

Fixes part of #455
prigaux added a commit that referenced this pull request Nov 20, 2026
handleLogoutRequests() compared the PTR name of REMOTE_ADDR with the
allowed client list. The PTR record is controlled by the owner of the
source address, so fall back to the plain IP unless the name resolves
back to it.

Fixes part of #455

Co-authored-by: Peter Wilfahrt <pw@pw.is>
@prigaux

prigaux commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

I committed squashed commits for "Do not let plain proxy chain entries match across the URL authority"

I committed a reworked commit for "Forward-confirm reverse DNS before trusting logout request client name".
NB: if you do not have extension "sockets", you get the previous behavior + a warning.

@prigaux prigaux closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants