-
Notifications
You must be signed in to change notification settings - Fork 31
Prevent parent directory access, custom Errors #49
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
FoamyGuy
merged 10 commits into
adafruit:main
from
michalpokusa:prevent-parent-directory-access
Apr 24, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
77bc821
Moved root_path from start and server_forever methods to constructor
michalpokusa e7a2deb
Minor changes in comments
michalpokusa d89e66e
Added checking for .. and backslash in path, introduced custom except…
michalpokusa 0467a27
Updated HTTPServer constructors to use "/static" as root path
michalpokusa c24466b
Changed secrets to settings.toml in examples
michalpokusa a545ca7
Added missing FORBIDDEN_403
michalpokusa 8a4f5c4
Extracted multiple send calls logic into decorator
michalpokusa bef9f76
Removing unnecessary slash in front of filename
michalpokusa 394c6f3
Merge commit 'a8b68f153b72b8c022eceec254abe129cf5f5802' into prevent-…
michalpokusa 9e173ef
Replaced os.environ to os.getenv
michalpokusa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
""" | ||
`adafruit_httpserver.exceptions` | ||
==================================================== | ||
* Author(s): Michał Pokusa | ||
""" | ||
|
||
|
||
class InvalidPathError(Exception): | ||
""" | ||
Parent class for all path related errors. | ||
""" | ||
|
||
|
||
class ParentDirectoryReferenceError(InvalidPathError): | ||
""" | ||
Path contains ``..``, a reference to the parent directory. | ||
""" | ||
|
||
def __init__(self, path: str) -> None: | ||
"""Creates a new ``ParentDirectoryReferenceError`` for the ``path``.""" | ||
super().__init__(f"Parent directory reference in path: {path}") | ||
|
||
|
||
class BackslashInPathError(InvalidPathError): | ||
""" | ||
Backslash ``\\`` in path. | ||
""" | ||
|
||
def __init__(self, path: str) -> None: | ||
"""Creates a new ``BackslashInPathError`` for the ``path``.""" | ||
super().__init__(f"Backslash in path: {path}") | ||
|
||
|
||
class ResponseAlreadySentError(Exception): | ||
""" | ||
Another ``HTTPResponse`` has already been sent. There can only be one per ``HTTPRequest``. | ||
""" | ||
|
||
|
||
class FileNotExistsError(Exception): | ||
""" | ||
Raised when a file does not exist. | ||
""" | ||
|
||
def __init__(self, path: str) -> None: | ||
""" | ||
Creates a new ``FileNotExistsError`` for the file at ``path``. | ||
""" | ||
super().__init__(f"File does not exist: {path}") |
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation builder should be able to use single backticks and produce cross references to other methods/functions here. Did that fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had problems with single ticks as it often couldn't find the member in X in module Y, not entirely sure why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal; I've also found it doesn't work under strange circumstances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhalbert Are there any more changes that you would like me to include?