Skip to content

Commit

Permalink
attempt at preventing cache poisoning, thanks Mirko
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Feb 23, 2025
1 parent 3d1a1a0 commit 0b83a76
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import importlib.machinery
import importlib.util
import inspect
import io
import json
import logging
import numbers
Expand Down Expand Up @@ -913,6 +912,10 @@ def URL( # pylint: disable=invalid-name
if scheme is not False:
original_url = request.environ.get("HTTP_ORIGIN") or request.url
orig_scheme, _, domain = original_url.split("/", 3)[:3]
expected_domain = os.environ.get("PY4WEB_DOMAIN")
if expected_domain and domain != expected_domain:
logging.warning(f"Possible cache poisoning blocked: url={original_url}")
domain = expected_domain
if scheme is True:
scheme = orig_scheme
elif scheme is None:
Expand Down

0 comments on commit 0b83a76

Please sign in to comment.