Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to check across multiple domains in URL validation #955

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,10 +912,16 @@ 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
expected_domains = [
domain_item.strip()
for domain_item in os.environ.get("PY4WEB_DOMAINS", "").split(",")
if domain_item
]
if expected_domains and domain not in expected_domains:
logging.warning(
"Possible cache poisoning blocked: url=%s", original_url
)
domain = expected_domains[0]
if scheme is True:
scheme = orig_scheme
elif scheme is None:
Expand Down