Skip to content

Commit 40af2fb

Browse files
authored
fix(api): disable signature verification for JWT decoding to handle upstream tokens
fix(api): change host binding to allow external access
1 parent 486ea47 commit 40af2fb

7 files changed

Lines changed: 9 additions & 6 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ FROM python:3.14.3-alpine AS runtime
2525
ENV PYTHONDONTWRITEBYTECODE=1 \
2626
PYTHONUNBUFFERED=1 \
2727
VIRTUAL_ENV=/app/.venv \
28-
PATH="/app/.venv/bin:$PATH"
28+
PATH="/app/.venv/bin:$PATH" \
29+
SUREHUB_HOST=0.0.0.0
2930

3031
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
3132

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies = [
1313
"dynaconf>=3.2.13,<4.0.0",
1414
"fastapi>=0.136.1,<1.0.0",
1515
"requests>=2.33.1,<3.0.0",
16-
"pyjwt (>=2.12.1,<3.0.0)",
16+
"pyjwt>=2.12.1,<3.0.0",
1717
]
1818

1919
[project.urls]

surehub_api/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
Validator('loglevel', is_in=['critical', 'error', 'warning', 'info', 'debug', 'trace']),
99
Validator('endpoint', must_exist=True, condition=lambda v: isinstance(v, str) and v.startswith('https://')),
1010
Validator('port', must_exist=True, condition=lambda v: isinstance(v, int) and 1 <= v <= 65535),
11+
Validator('host', must_exist=True),
1112
],
1213
)

surehub_api/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def main():
7272

7373
uvicorn.run(
7474
"surehub_api.main:app",
75+
host=settings.host,
7576
port=settings.port,
76-
host="127.0.0.1",
7777
log_level=settings.loglevel,
7878
log_config=log_config,
7979
reload=settings.debug

surehub_api/services/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _get_token(force_refresh: bool = False) -> str:
9393

9494
def _parse_expiry(token: str) -> datetime:
9595
try:
96-
payload = jwt.decode(token)
96+
payload = jwt.decode(token, options={"verify_signature": False}) # NOSONAR(S5659)
9797
return datetime.fromtimestamp(payload["exp"], tz=timezone.utc) - _TOKEN_EXPIRY_MARGIN
9898
except (jwt.exceptions.DecodeError, KeyError) as exc:
9999
raise HTTPException(status_code=502, detail=f"Invalid token from upstream: {exc}") from exc
@@ -128,4 +128,4 @@ def _login() -> str:
128128
if attempt == _LOGIN_RETRIES - 1:
129129
raise requests.exceptions.RequestException(
130130
f"Upstream auth unavailable after {_LOGIN_RETRIES} attempts: {exc}"
131-
) from exc
131+
) from exc

surehub_api/settings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
loglevel: "info"
22
endpoint: "https://app-api.production.surehub.io"
3+
host: "127.0.0.1"
34
port: 3001
45
debug: false
56
cors:

0 commit comments

Comments
 (0)