mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
trusted_sources was checked with QString::contains. A dual-stack listener reports a local proxy as ::ffff:127.0.0.1, which never matches the default "127.0.0.1,::1". Behind nginx the forwarded client IP header was then ignored, every websocket user shared the proxy's address, and logins failed with "too many concurrent connections" once max_users_per_address was reached. Add isTrustedSource(), which parses each entry as a QHostAddress and compares exact addresses with IPv4-mapped addresses normalized, and use it at all four call sites. The ban command also read server/trusted_sources instead of the documented security/trusted_sources; it now uses the same getter. Entries that are not IP addresses are logged at startup since they no longer match anything. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
808 B
C
20 lines
808 B
C
#ifndef TRUSTED_SOURCES_H
|
|
#define TRUSTED_SOURCES_H
|
|
|
|
#include <QHostAddress>
|
|
#include <QString>
|
|
|
|
/**
|
|
* @brief True if @p address is listed in the comma-separated @p trustedSources (security/trusted_sources).
|
|
*
|
|
* Entries are parsed as addresses and compared exactly, never as substrings, so
|
|
* 27.0.0.1 does not match 127.0.0.1. IPv4-mapped IPv6 addresses compare equal to
|
|
* their IPv4 form: a dual-stack listener reports a local proxy as ::ffff:127.0.0.1,
|
|
* which matches a 127.0.0.1 entry. Malformed entries and null addresses never match.
|
|
*/
|
|
bool isTrustedSource(const QString &trustedSources, const QHostAddress &address);
|
|
|
|
/** @brief Overload for an address in string form; an unparsable string never matches. */
|
|
bool isTrustedSource(const QString &trustedSources, const QString &address);
|
|
|
|
#endif
|