Add path traversal validation in error.py following notion-sdk-js#312
Merged
ramnes merged 3 commits intoramnes:mainfrom Feb 2, 2026
Merged
Conversation
- Implemented `validate_request_path` to prevent path traversal attacks
…date_request_path` function - Simplified the logic around `decoded = unquote(path)`
…ting `%2e` in request paths
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #312 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 480 496 +16
=========================================
+ Hits 480 496 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Owner
|
Great, thanks! |
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.
Summary
InvalidPathParameterErrorclass for path traversal validation errorsvalidate_request_path()function to detect path traversal sequencesClientErrorCode.InvalidPathParameterenum valueerrors.pyThis PR follows the JavaScript SDK's PR #661 to add path traversal prevention.
Related Issue #283
Differences from JS SDK
The Python implementation has two intentional differences from the JS version:
1. Simplified URL-encoded detection
Using
inwithstr.lower()is more Pythonic than using regex for simple substring matching. So that we do not need toimport reand it is more straightforward and easier to read. The reason for using a regular expression in JavaScript is thatString.prototype.includes()does not support a case-insensitive option.2. Removed try-except block
Python's
urllib.parse.unquote()handles invalid percent-encoding gracefully by preserving the original characters, unlike JavaScript'sdecodeURIComponent()which throwsURIError. The try-except block is unnecessary in Python. Furthermore, it makes it difficult to achieve 100% coverage.