Register the endpoints list without a trailing slash, and stop hiding its errors
An endpoint reported telemetry correctly for hours while the Fleet page showed
"No endpoints found". The PC detail page displayed its panels the whole time, so
ingest was plainly working; only the list was empty.
The list route was the one route in 331 paths registered with a trailing slash:
@endpoints_bp.route('/', methods=['GET']) -> /api/endpoints/
The browser client calls it without one, so Flask answered a 308 redirect to an
ABSOLUTE url. On dev that resolves and nobody notices. Behind the IIS subpath it
cannot: with no ProxyFix, Werkzeug builds that Location from the scheme and host
it believes it has, so it emitted http:// and dropped the /shopdb prefix. A
browser will not follow an https page to http, the request failed, and the
page's catch block rendered the empty state.
Every other route in the plugin worked throughout, because none of them carries
a trailing slash - the detail panels call /endpoints/asset/<id>/status and were
never redirected. Detail works, list empty is the signature of this bug.
Registered as '' now, so the rule is /api/endpoints. That is what
CONTRIBUTING.md's API section spells and what every other list route in the
product already did. The inventory and the generated spec are updated to match.
Also here:
- tests/test_core/test_no_redirecting_routes.py fails the build if any /api
rule is registered with a trailing slash and strict slashes. Verified by
planting the violation: it named the offending route, then passed once
reverted. It takes the shared app fixture rather than building its own
application - doing that rebinds SQLAlchemy and leaves the NEXT module
without tables, which showed up as three unrelated "no such table: settings"
failures visible only in a full run.
- The Fleet page now renders "Could not load endpoints (HTTP nnn). This is a
failed request, not an empty fleet." A list that reports a 403 and an empty
fleet identically is what made this take as long as it did.
- TRUSTED_PROXY_COUNT (default 0) applies ProxyFix when set. Off by default on
purpose: it makes X-Forwarded-* trusted, and a client can send those itself,
while the login rate limit and account lockout are keyed on the client
address. Set it to 1 on an instance behind IIS.
Full suite 2124 passed, vitest 260 passed, naming and docs gates green.
This commit is contained in:
@@ -131,6 +131,28 @@ def create_app(config_name: str = None) -> Flask:
|
||||
if envname.startswith('COLLECTOR_API_KEY_') and envvalue:
|
||||
app.config[envname] = envvalue
|
||||
|
||||
# Behind a reverse proxy (IIS at /shopdb, nginx, a load balancer), the app
|
||||
# sees the PROXY's connection, not the browser's: scheme http even though
|
||||
# the user is on https, the proxy's host, the proxy's IP. Anything Flask
|
||||
# builds from that is wrong at the browser - an absolute redirect Location
|
||||
# above all, which is how a trailing-slash redirect on the endpoints list
|
||||
# sent an https page to an http URL the browser then refused to follow.
|
||||
#
|
||||
# OFF BY DEFAULT AND DELIBERATELY. ProxyFix makes the app TRUST
|
||||
# X-Forwarded-* headers, and a client can send those itself. Enabled with no
|
||||
# proxy in front, any caller can claim a different scheme or source IP -
|
||||
# which matters here because the login rate limit and the lockout are keyed
|
||||
# on the client address. Set TRUSTED_PROXY_COUNT to the number of proxies
|
||||
# actually in front of this instance (1 for a single IIS or nginx), and only
|
||||
# when one really is.
|
||||
proxycount = app.config.get('TRUSTED_PROXY_COUNT', 0)
|
||||
if proxycount:
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
app.wsgi_app = ProxyFix(
|
||||
app.wsgi_app,
|
||||
x_for=proxycount, x_proto=proxycount,
|
||||
x_host=proxycount, x_prefix=proxycount)
|
||||
|
||||
# Ensure instance folder exists
|
||||
os.makedirs(app.instance_path, exist_ok=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user