Skip to content

Commit 338767f

Browse files
committed
fix(api): deny all API requests
There seems to be a relation to the persistent connections of the HTTP/2 (initial connection with TLS handshake is done to the dashboard; SNI is ‹dashboard.packit.dev› and with the same SNI it makes a request to the Packit Service API, thus resulting in the request being routed to the dashboard rather than the production API itself, since the routing for TLS Passthrough connections is done based on the SNI). Therefore yield 421 for each such misdirected request to force the browser to open a new connection. Fixes packit/packit-service#2529 Signed-off-by: Matej Focko <mfocko@redhat.com>
1 parent 3bc9e5c commit 338767f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

packit_dashboard/api/routes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright Contributors to the Packit project.
2+
# SPDX-License-Identifier: MIT
3+
4+
from logging import getLogger
5+
6+
from flask import Blueprint
7+
from flask_cors import CORS
8+
9+
10+
logger = getLogger("packit_dashboard")
11+
api = Blueprint(
12+
"api",
13+
__name__,
14+
)
15+
CORS(api)
16+
17+
18+
@api.route("/api/", defaults={"path": ""})
19+
@api.route("/api/<path:path>")
20+
def drop(path):
21+
"""
22+
Return ‹421› for all misdirected requests that reused / used persistent
23+
HTTP/2 connection with the wrong SNI and got routed via OpenShift to the
24+
dashboard rather than the actual Packit Service API endpoint.
25+
"""
26+
return ("", 421)

packit_dashboard/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from flask import Flask
77
from flask_talisman import Talisman
88

9+
from packit_dashboard.api.routes import api
910
from packit_dashboard.home.routes import home
1011

1112
app = Flask(
@@ -16,6 +17,7 @@
1617
# Note: Declare any other flask blueprints or routes above this.
1718
# Routes declared below this will be rendered by React
1819
app.register_blueprint(home)
20+
app.register_blueprint(api)
1921

2022

2123
# Enable CSP and HSTS

0 commit comments

Comments
 (0)