Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this monorepo.

## backends v3.0.1 — 2026-11-14 (`bug-report-py` 3.0.1)

Two fixes to `create_proxy_blueprint` from the first review of the seal viewer's move. No contract change.

- **A refusal of the APP is a 502, never a 401/403.** The service marks what its `guard` refuses (no, bad or untrusted
app token) with `X-Leap-Trust-Refusal: 1`; the proxy turns that 401/403 into a 502 `{"error": "the reports service
refused this app"}` and logs the real status and body. A seal laptop reads a 401 from its hosted app as "your station
pass was refused", signs the operator out and holds the report for good: a setup mistake must not look like that. The
blueprint's own 403 (not an admin) and 401 (sign in to vote) are about the person and pass through. A service older
than 3.0.1 sets no marker, so its refusals still pass through as they were.
- **A list with no `app` query asks for this app's own reports** (`app=<its app>` is added). The queue and the open count
no longer show every app's. An explicit `app` passes through as given.

## backends v3.0.0 — 2026-11-14 (`bug-report-py` 3.0.0)

One central store for every app's reports (design: `CENTRAL-STORE.md`). The Python library only; nothing is
Expand Down
6 changes: 5 additions & 1 deletion packages/backend-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ Every route (POST, list, detail, PATCH, vote, screenshot) is forwarded with its
and the service's status, body, content type and `Location` come back unchanged (a 302 to a signed screenshot URL is
not followed). Each forwarded request carries `Authorization: Bearer <token_provider()>`, `X-Leap-Actor-Email` and
`X-Leap-Actor-Name` (percent-encoded) from `person_provider()`, and `X-Leap-App: <app>`; the browser's own
`Authorization` and `X-Leap-*` headers are dropped. A `..` path segment is refused (400). A service that cannot be reached is a 502, and a token or identity that cannot be
`Authorization` and `X-Leap-*` headers are dropped. A 401/403 the service marks as a refusal of the APP (`X-Leap-Trust-Refusal`, set by `guard=`; 3.0.1) comes back as a
502 `the reports service refused this app`, the real status and body going to the log: a client that reads a 401 as "your
sign-in failed" (a seal laptop's outbox) must never be told that about a setup mistake. The blueprint's own 403 (not an admin)
and 401 (sign in to vote) pass through. A list with no `app` query is asked for as `app=<this app>` (3.0.1); an explicit `app`
passes through. A `..` path segment is refused (400). A service that cannot be reached is a 502, and a token or identity that cannot be
produced is a 502 with nothing sent; the 502 bodies are generic (the reason goes to the log, not the browser). Standard library only (urllib).

## The service side: who is calling (3.0.0)
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-python/bug_report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
valid_bug_id,
)

__version__ = "3.0.0"
__version__ = "3.0.1"

from . import contract
from .contract import (
Expand Down
9 changes: 7 additions & 2 deletions packages/backend-python/bug_report/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
screenshot_content_type,
valid_bug_id,
)
from .trust import ENVIRON_KEY
from .trust import ENVIRON_KEY, TRUST_REFUSAL_HEADER
from .store import (
AuditEntry,
BugRecord,
Expand Down Expand Up @@ -124,7 +124,12 @@ def _guard():
refused = guard(request)
if refused:
status, message = refused
return jsonify({"error": message}), status
resp = jsonify({"error": message})
resp.status_code = status
# Said apart from the blueprint's own 401/403 (sign in to vote, not an admin): a proxy turns
# THIS one into a 502, because the app was refused, not the person (3.0.1).
resp.headers[TRUST_REFUSAL_HEADER] = "1"
return resp
return None

@bp.after_request
Expand Down
21 changes: 18 additions & 3 deletions packages/backend-python/bug_report/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
and content type come back unchanged. Each forwarded request carries
``Authorization: Bearer <token_provider()>``, ``X-Leap-Actor-Email`` /
``X-Leap-Actor-Name`` (percent-encoded; the service decodes) from
``person_provider()``, and ``X-Leap-App: <app>``. Any ``Authorization`` or
``person_provider()``, and ``X-Leap-App: <app>``. A list with no ``app`` query is
asked for this app's own reports. A 401/403 the service marks as a refusal of the
APP (``X-Leap-Trust-Refusal``) comes back as a 502; its other 401/403 (not an
admin, sign in to vote) pass through. Any ``Authorization`` or
``X-Leap-*`` header the browser sent is dropped: the app's own identity, not
the page's claim, is what the service looks at. Standard library only.
"""
Expand All @@ -30,6 +33,8 @@

from flask import Blueprint, Response, request

from .trust import TRUST_REFUSAL_HEADER

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -68,8 +73,13 @@ def forward(rest: str):
if any(seg in ("..", ".") or "\\" in seg for seg in rest.split("/")):
return _err(400, "invalid path")
url = base + ("/" + rest if rest else "")
if request.query_string:
url += "?" + request.query_string.decode("latin-1")
query = request.query_string.decode("latin-1")
# The list is this app's own reports unless the caller says otherwise (3.0.1): the open count and
# the queue must not show every app's, which is what the service gives a trusted app with no filter.
if request.method == "GET" and not rest and "app" not in request.args:
query = (query + "&" if query else "") + "app=" + quote(app, safe="")
if query:
url += "?" + query
try:
person = person_provider() or {}
headers = {h: request.headers[h] for h in _FORWARD if h in request.headers}
Expand Down Expand Up @@ -97,6 +107,11 @@ def forward(rest: str):
return _err(502, "the reports service is not reachable")

def _relay(status, body, upstream_headers):
if status in (401, 403) and upstream_headers.get(TRUST_REFUSAL_HEADER):
# The service refused THIS APP (a setup mistake), not the person. A 401 here would read, to a
# client that treats 401 as "your sign-in failed" (a seal laptop's outbox), as the person's.
log.warning("reports proxy (%s): the service refused this app: %s %s", app, status, body[:300])
return _err(502, "the reports service refused this app")
resp = Response(body, status=status)
for h in _BACK:
v = upstream_headers.get(h)
Expand Down
4 changes: 4 additions & 0 deletions packages/backend-python/bug_report/trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#: where the resolved caller is cached for the life of one request
ENVIRON_KEY = "bug_report.caller"

#: set on a response the ``guard`` refused (no, bad or untrusted app token), so a proxy can tell "the app
#: was refused" from the blueprint's own 401/403 about the person (3.0.1)
TRUST_REFUSAL_HEADER = "X-Leap-Trust-Refusal"


@dataclass
class Caller:
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bug-report-py"
version = "3.0.0"
version = "3.0.1"
description = "Flask blueprint + storage interface implementing the bug-report-widget API spec."
readme = "README.md"
license = { text = "MIT" }
Expand Down
40 changes: 35 additions & 5 deletions packages/backend-python/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,51 @@ def test_a_non_admin_person_gets_the_central_403_through_the_proxy(front):
assert front.c.post(f"/api/bugs/{bid}/vote").status_code == 200 # voting is for anyone signed in


def test_an_untrusted_app_token_is_refused_403_on_every_route(front):
def test_an_untrusted_app_is_a_502_on_every_route_not_a_403(front):
"""The app was refused, not the person: a 403 here would read as the person's (3.0.1)."""
bid = file(front)
front.token[0] = "ok:client-stranger"
for method, path in (("post", "/api/bugs"), ("get", "/api/bugs"), ("get", f"/api/bugs/{bid}"),
("patch", f"/api/bugs/{bid}"), ("post", f"/api/bugs/{bid}/vote"),
("get", f"/api/bugs/{bid}/screenshot")):
r = getattr(front.c, method)(path, json={"details": "x", "status": "triaged"} if method != "get" else None)
assert r.status_code == 403, (method, path)
assert r.get_json()["error"] == "caller is not a trusted app"
assert r.status_code == 502, (method, path)
assert r.get_json() == {"error": "the reports service refused this app"}


def test_a_token_that_does_not_verify_is_401(front):
def test_a_token_that_does_not_verify_is_a_502_not_a_401(front):
"""A 401 from the proxy reads, to a seal laptop's outbox, as "your station pass was refused" (3.0.1)."""
front.token[0] = "forged"
r = front.c.post("/api/bugs", json={"details": "x"})
assert r.status_code == 401
assert r.status_code == 502 and r.get_json() == {"error": "the reports service refused this app"}


def test_the_real_status_and_body_of_a_refusal_go_to_the_log(front, caplog):
front.token[0] = "ok:client-stranger"
with caplog.at_level("WARNING"):
front.c.get("/api/bugs")
assert "403" in caplog.text and "caller is not a trusted app" in caplog.text


def test_not_signed_in_to_vote_is_still_a_401_through_the_proxy(front):
bid = file(front)
front.person[0] = {"email": "", "name": ""}
assert front.c.post(f"/api/bugs/{bid}/vote").status_code == 401 # the person's, not the app's


def test_a_list_is_this_apps_own_reports_unless_it_asks_otherwise(central):
s, store, _ = central
seal = Front(s.url, app_name="sealviewer")
seal.token[0] = "ok:client-seal"
plc = Front(s.url)
mine = file(seal)
theirs = file(plc)
ids = lambda r: [b["id"] for b in r.get_json()["bugs"]] # noqa: E731
assert ids(seal.c.get("/api/bugs?status=open&days=365")) == [mine] # what the open count asks
assert ids(plc.c.get("/api/bugs?status=open&days=365")) == [theirs]
assert ids(seal.c.get("/api/bugs")) == [mine]
assert sorted(ids(seal.c.get("/api/bugs?app=placements"))) == [theirs] # an explicit app passes as given
assert store.get_bug(theirs).app == "placements"


def test_x_leap_app_that_disagrees_with_the_token_loses_and_the_response_says_so(central):
Expand Down
Loading