Skip to content

mtconnect: optional user pages served by the embedded HTTP agent - #4447

Open
grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:mtconnect-userpages
Open

mtconnect: optional user pages served by the embedded HTTP agent#4447
grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:mtconnect-userpages

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

Supersedes #4406. The author closed it after review and is fine with me taking it over; the first commit is his original change, kept as authored.

Adds optional user pages to the embedded MTConnect HTTP agent: [MTCONNECT]USER_PAGES points at a directory of html/assets, files are served under /html/<name>, and a relative path resolves against the ini file's directory.

Hardening on top of #4406:

  • Containment uses os.path.commonpath() on canonicalized paths. The plain startswith() prefix check was bypassable via a sibling directory sharing the name prefix ("pages" vs "pages_evil").
  • Files are read as bytes with the Content-Type from mimetypes. Text-mode reads 500 on binary assets, and browsers refuse to run js/css served as text/html, so multi-file pages never loaded.
  • The /html/<name> route prefix is documented in the man page.
  • test_mtc.py covers serving, content type, and traversal rejection (including the sibling-prefix bypass).

odippel@ypsilon.net and others added 2 commits August 18, 2026 11:19
- Canonicalize USER_PAGES once and check containment with commonpath();
  a plain startswith() prefix check is bypassable via a sibling directory
  sharing the name prefix (pages vs pages_evil).
- Read files as bytes and pick the Content-Type with mimetypes; a text-mode
  read 500s on binary assets, and browsers refuse to run js/css served as
  text/html, so multi-file pages never loaded.
- Document the /html/<name> route prefix in the man page.
- Cover serving, content type, and traversal rejection in test_mtc.py.
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.

1 participant