Skip to content
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

Add send_file warning #4

Merged
merged 3 commits into from
Jan 31, 2020
Merged

Add send_file warning #4

merged 3 commits into from
Jan 31, 2020

Conversation

ulziibay
Copy link
Contributor

@ulziibay ulziibay commented Jan 28, 2020

Adds a check when there might be a dataflow from user input to a sink.
"How to serve static files in Flask" is the most asked question in Stackoverflow for Flask. Hence, this will be a popular check if we do it right.

Pending def $X(filename: $Y, ...): support integration in https://github.com/returntocorp/sgrep.

Testing:

  1. Run rule
sgrep-lint ~/Workspace/sgrep-rules/python/flask/secure-static-file-serve.yaml ~/Workspace/sgrep-rules/tests/python/flask/send_static_file/test_send_file_without_path_sanitization.py| jq
  1. See it fire on
@app.route("/<path:filename>")
def download_file(filename):
  return send_file(filename) .  ## CATCHES THIS

@ulziibay ulziibay requested review from aryx and ievans January 28, 2020 01:09
@ulziibay ulziibay mentioned this pull request Jan 28, 2020
5 tasks
@ulziibay ulziibay marked this pull request as ready for review January 30, 2020 00:12
@ulziibay ulziibay merged commit cc16cb9 into master Jan 31, 2020
- id: avoid_send_file_without_path_sanitization
patterns:
- pattern-inside: |
def $X(filename):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulziibay shouldn't filename be a metavariable, eg $F?

- id: avoid_send_file_without_path_sanitization
patterns:
- pattern-inside: |
def $X(filename):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would have decorator support here semgrep/semgrep#29

@DrewDennison DrewDennison deleted the uo/flask_securit_static_file branch February 1, 2020 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants