Skip to content

Fix #2326 - Redirect to localhost when on 0.0.0.0 #2328

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

Merged
merged 2 commits into from
Apr 14, 2025

Conversation

WebReflection
Copy link
Contributor

Description

This MR fixes #2326 by simply avoiding users to visit directly http://0.0.0.0 as:

  • most browsers refuse to even visit that address anyway (Windows)
  • Firefox redirects automatically to 127.0.0.1 for loopback
  • the 0.0.0.0 is not really an address and nothing on the Web can reach that address

So with this simple check that error people using python -m http.server, which hints to reach that broken address by default, will be redirected to localhost.

Changes

  • add a top-level import that triggers a redirect if the address is wrong

Checklist

  • I have checked make build works locally.
  • I have created / updated documentation for this change (if applicable).

@WebReflection WebReflection requested review from Copilot and ntoll April 7, 2025 15:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

core/src/zero-redirect.js:4

  • Catching all errors via a generic catch may inadvertently hide unexpected errors unrelated to crypto.randomUUID() support. Consider explicitly checking for the existence of crypto.randomUUID() if possible.
catch (_) { // eslint-disable-line

core/src/zero-redirect.js:5

  • [nitpick] While the conditional check is clear, consider enclosing the subsequent redirection action in braces to improve clarity and reduce potential errors if additional lines are added later.
if (location.href.startsWith('http://0.0.0.0'))

try {
crypto.randomUUID();
} catch (_) {
// eslint-disable-next-line
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre commit here is likely breaking the build ... that comment is meant to be before the catch, not after

Copy link
Member

@ntoll ntoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@WebReflection WebReflection merged commit 16ebc50 into pyscript:main Apr 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crypto.randomUUID is not a function when running locally
2 participants