mtconnect: optional user pages served by the embedded HTTP agent - #4447
Open
grandixximo wants to merge 2 commits into
Open
mtconnect: optional user pages served by the embedded HTTP agent#4447grandixximo wants to merge 2 commits into
grandixximo wants to merge 2 commits into
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
os.path.commonpath()on canonicalized paths. The plainstartswith()prefix check was bypassable via a sibling directory sharing the name prefix ("pages" vs "pages_evil").mimetypes. Text-mode reads 500 on binary assets, and browsers refuse to run js/css served astext/html, so multi-file pages never loaded./html/<name>route prefix is documented in the man page.test_mtc.pycovers serving, content type, and traversal rejection (including the sibling-prefix bypass).