8000 webrepl: Allow the page to run from the device (over HTTP). by jimmo · Pull Request #70 · micropython/webrepl · GitHub
[go: up one dir, main page]

Skip to content

webrepl: Allow the page to run from the device (over HTTP). #70

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

Closed
wants to merge 3 commits into from

Conversation

jimmo
Copy link
Member
@jimmo jimmo commented Jul 20, 2022

This is an attempt to solve the issue where the publicly-hosted webrepl on https://micropython.org/webrepl is currently non-functional due to the page being served via https, but attempting to connect to a device hosting a non-secure websocket. See micropython/micropython#5266

The new behaviour is that the device itself serves up the webrepl client, but in order to minimise space on the device it is a very minimal page that contains a script tag that loads https://micropython.org/webrepl/webrepl_content.js. This then document.write's the HTML content that would have otherwise been loaded from https://micropython.org/webrepl.

So now the page is allowed to access the device over non-secure websocket (as the page itself is http, despite the resources were loaded via https), and furthermore it's same-origin.

See edit-with-link-to-main-repo-PR-when-submitted for the corresponding change to the on-device code.

This PR contains:

  • A minor refactoring of websocket_cli.py to remove unused code in websocket_helper.py.
  • Splitting the css/js out of webrepl.html. Not strictly necessary for this PR but it hugely simplifies the conversion to webrepl_content.js as there's only HTML to escape.
  • Updates to webrepl.html and webrepl.js to match the new behaviour (including updating the https error and the logic to select the default ws host).

jimmo added 3 commits July 20, 2022 12:15
websocket_helper.py wasn't useful as a standalone library outside of
webrepl_cli.py. Removes unused server_handshake function.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The device will respond to a non-WS request with a simple page that loads
websocket_content.js from a static host (http or https). However, even
if the resources are https, the page is still http and therefore allows
requesting to a WS (not WSS) websocket on the device.

Updated the warning about HTTPS and the default-ws-URL logic.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
@jimmo
Copy link
Member Author
jimmo commented Jul 20, 2022

There are two other alternatives for solving this:

  • Make the device serve up the entire webrepl client (term.js, etc). I don't think this is sensible, it's just a waste of flash.
  • Make the device support secure websockets. This is also a non-trivial flash (and RAM) burden, and there's still questions around how to actually put a valid cert on the device (it can't be self-signed).

Also note that webrepl_content.js shouldn't be included in this commit (and I will add a .gitignore for it) but it's just there for now for testing (so it will be served up by gitcdn).

@dpgeorge
Copy link
Member

Very good, thank you!

Merged in 17ba41a through fff7b87

@dpgeorge dpgeorge closed this Jul 22, 2022
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.

2 participants
0