From 4c7246f37124b5fd7e2081e236c904059f4e5cd8 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 20 Nov 2026 17:06:32 +0000 Subject: [PATCH 1/2] Restrict forced dashboard refreshes to local requests --- .github/workflows/check.yml | 2 ++ master/custom/release_dashboard.py | 10 ++++++- tests/test_release_dashboard_local_refresh.py | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/test_release_dashboard_local_refresh.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index bf07b26d..54958922 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,6 +26,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Check configuration run: make check PIP=pip BUILDBOT=buildbot PYTHON_VERSION=${{ matrix.python-version }} + - name: Check custom components + run: PYTHONPATH=master python -m unittest discover -s tests - name: Compare configuration reports run: | # Use the same formatter for both configurations, including older main revisions. diff --git a/master/custom/release_dashboard.py b/master/custom/release_dashboard.py index 3f0c024d..4560ab35 100644 --- a/master/custom/release_dashboard.py +++ b/master/custom/release_dashboard.py @@ -34,6 +34,14 @@ BRANCHES_URL = "https://peps.python.org/api/release-cycle.json" +def _is_local_refresh(): + return ( + request.args.get("refresh", "").lower() in {"1", "yes", "true"} + and request.remote_addr in {'127.0.0.1', '::1'} + and not request.headers.get('X-Forwarded-For') + ) + + def _gimme_error(func): """Debug decorator to turn AttributeError into a different Exception @@ -750,7 +758,7 @@ def __init__(self, test_result_dir=None): @self.flask_app.route('/') @self.flask_app.route("/index.html") def main(): - force_refresh = request.args.get("refresh", "").lower() in {"1", "yes", "true"} + force_refresh = _is_local_refresh() if self.cache is not None and not force_refresh: result, deadline = self.cache diff --git a/tests/test_release_dashboard_local_refresh.py b/tests/test_release_dashboard_local_refresh.py new file mode 100644 index 00000000..a328ad9f --- /dev/null +++ b/tests/test_release_dashboard_local_refresh.py @@ -0,0 +1,26 @@ +import unittest + +from flask import Flask + +from custom import release_dashboard as dashboard + + +class LocalRefreshTests(unittest.TestCase): + def setUp(self): + self.app = Flask(__name__) + + def test_proxy_cannot_force_refresh(self): + with self.app.test_request_context('/?refresh=true', headers={'X-Forwarded-For': '203.0.113.1'}, environ_overrides={'REMOTE_ADDR': '127.0.0.1'}): + self.assertFalse(dashboard._is_local_refresh()) + + def test_remote_address_cannot_force_refresh(self): + with self.app.test_request_context('/?refresh=true', environ_overrides={'REMOTE_ADDR': '203.0.113.1'}): + self.assertFalse(dashboard._is_local_refresh()) + + def test_loopback_can_force_refresh(self): + with self.app.test_request_context('/?refresh=true', environ_overrides={'REMOTE_ADDR': '127.0.0.1'}): + self.assertTrue(dashboard._is_local_refresh()) + + def test_loopback_without_refresh_flag_does_not_force_refresh(self): + with self.app.test_request_context('/', environ_overrides={'REMOTE_ADDR': '127.0.0.1'}): + self.assertFalse(dashboard._is_local_refresh()) From 481eb9e4bb9f3168fde34097b0c26a75d390d8c4 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 20 Nov 2026 18:27:00 +0000 Subject: [PATCH 2/2] Inline the local refresh check --- .github/workflows/check.yml | 2 -- master/custom/release_dashboard.py | 14 ++++------ tests/test_release_dashboard_local_refresh.py | 26 ------------------- 3 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 tests/test_release_dashboard_local_refresh.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 54958922..bf07b26d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,8 +26,6 @@ jobs: python-version: ${{ matrix.python-version }} - name: Check configuration run: make check PIP=pip BUILDBOT=buildbot PYTHON_VERSION=${{ matrix.python-version }} - - name: Check custom components - run: PYTHONPATH=master python -m unittest discover -s tests - name: Compare configuration reports run: | # Use the same formatter for both configurations, including older main revisions. diff --git a/master/custom/release_dashboard.py b/master/custom/release_dashboard.py index 4560ab35..a22a9777 100644 --- a/master/custom/release_dashboard.py +++ b/master/custom/release_dashboard.py @@ -34,14 +34,6 @@ BRANCHES_URL = "https://peps.python.org/api/release-cycle.json" -def _is_local_refresh(): - return ( - request.args.get("refresh", "").lower() in {"1", "yes", "true"} - and request.remote_addr in {'127.0.0.1', '::1'} - and not request.headers.get('X-Forwarded-For') - ) - - def _gimme_error(func): """Debug decorator to turn AttributeError into a different Exception @@ -758,7 +750,11 @@ def __init__(self, test_result_dir=None): @self.flask_app.route('/') @self.flask_app.route("/index.html") def main(): - force_refresh = _is_local_refresh() + force_refresh = ( + request.args.get("refresh", "").lower() in {"1", "yes", "true"} + and request.remote_addr in {'127.0.0.1', '::1'} + and not request.headers.get('X-Forwarded-For') + ) if self.cache is not None and not force_refresh: result, deadline = self.cache diff --git a/tests/test_release_dashboard_local_refresh.py b/tests/test_release_dashboard_local_refresh.py deleted file mode 100644 index a328ad9f..00000000 --- a/tests/test_release_dashboard_local_refresh.py +++ /dev/null @@ -1,26 +0,0 @@ -import unittest - -from flask import Flask - -from custom import release_dashboard as dashboard - - -class LocalRefreshTests(unittest.TestCase): - def setUp(self): - self.app = Flask(__name__) - - def test_proxy_cannot_force_refresh(self): - with self.app.test_request_context('/?refresh=true', headers={'X-Forwarded-For': '203.0.113.1'}, environ_overrides={'REMOTE_ADDR': '127.0.0.1'}): - self.assertFalse(dashboard._is_local_refresh()) - - def test_remote_address_cannot_force_refresh(self): - with self.app.test_request_context('/?refresh=true', environ_overrides={'REMOTE_ADDR': '203.0.113.1'}): - self.assertFalse(dashboard._is_local_refresh()) - - def test_loopback_can_force_refresh(self): - with self.app.test_request_context('/?refresh=true', environ_overrides={'REMOTE_ADDR': '127.0.0.1'}): - self.assertTrue(dashboard._is_local_refresh()) - - def test_loopback_without_refresh_flag_does_not_force_refresh(self): - with self.app.test_request_context('/', environ_overrides={'REMOTE_ADDR': '127.0.0.1'}): - self.assertFalse(dashboard._is_local_refresh())