Skip to content

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

Merged
WebReflection merged 2 commits into
pyscript:mainfrom
WebReflection:issue-2326
Apr 14, 2025
Merged

Fix #2326 - Redirect to localhost when on 0.0.0.0#2328
WebReflection merged 2 commits into
pyscript:mainfrom
WebReflection:issue-2326

Conversation

@WebReflection

Copy link
Copy Markdown
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

Copilot AI left a comment

Copy link
Copy Markdown

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'))

Comment thread core/src/zero-redirect.js Outdated
try {
crypto.randomUUID();
} catch (_) {
// eslint-disable-next-line

Copy link
Copy Markdown
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

@ntoll ntoll left a comment

Copy link
Copy Markdown
Member

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
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

3 participants