-
Notifications
You must be signed in to change notification settings - Fork 50
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
Parse array slices without eval(<user_input>)
#752
Parse array slices without eval(<user_input>)
#752
Conversation
Echoing comments from #751 for visiblity:
tiled/tiled/server/dependencies.py Line 163 in 9059fd0
|
tiled/server/dependencies.py
Outdated
@@ -160,19 +163,16 @@ def expected_shape( | |||
|
|||
|
|||
def slice_( | |||
slice: str = Query(None, pattern="^[-0-9,:]*$"), | |||
slice: Optional[str] = None, |
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 would like to retain a regex pattern. It no longer has a security function, with eval
removed, but it does have a role in both documenting the acceptable inputs in the OpenAPI spec and providing a detailed error message. (See my example in PR Conversation tab.)
Additionally, it would be useful to test that all the failing examples (typo and malicious) will not match the regex, and therefore should get bounced by FastAPI before they parsed by our code. That is, the ValueError
or TypeError
should never actually get raised when used in integration with FastAPI.
Finally, the regex pattern I've used here is a little under-specified. It is sufficient to block malicious examples but not sufficient to block malformed (e.g. typo-ed) examples. A more precise regex was drafted in these lines of a dormant PR. Perhaps that would be reused here (with the mean
aspect removed for now).
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.
Thanks for the feedback! I'll write a commit with updates.
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 agree. The rest looks good to me.
1696e9a
to
f23622d
Compare
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.
Looks good. A couple of minor things are noted in the comments.
e6fad7b
to
49c2bea
Compare
I rebased on While resolving conflicts in |
This PR addresses issue #751