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 Privacy Request Input Sanitization #2655

Merged
merged 18 commits into from
Mar 15, 2023

Conversation

ThomasLaPiana
Copy link
Contributor

@ThomasLaPiana ThomasLaPiana commented Feb 21, 2023

Closes https://github.com/ethyca/security-issues/issues/3
Closes https://github.com/ethyca/security-issues/issues/4

Code Changes

  • create a PhoneNumber class with validation that can be reused across the application
  • update phone number fields to use the new class
  • update email fields to use EmailStr instead of str
  • create a custom SafeStr class that sanitizes input values
  • add testing for new classes
  • Update the privacy request schemas to use SafeStr in place of str

Steps to Confirm

  • confirm that the above-linked issues have been fixed
  • poke around at other endpoints

Pre-Merge Checklist

Description Of Changes

This PR adds new custom types designed to improve automatic validation and sanitization of user input data. It also applies these new custom types to the privacy request endpoints to remediate the above-linked issues

@ThomasLaPiana ThomasLaPiana self-assigned this Feb 21, 2023
@cypress
Copy link

cypress bot commented Feb 21, 2023

Passing run #813 ↗︎

0 3 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge 5c1b583 into cf7bcd2...
Project: fides Commit: 6e7d3938b4 ℹ️
Status: Passed Duration: 00:39 💡
Started: Mar 15, 2023 8:49 AM Ended: Mar 15, 2023 8:50 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@codecov
Copy link

codecov bot commented Feb 21, 2023

Codecov Report

Patch coverage: 91.66% and project coverage change: +0.20 🎉

Comparison is base (5194405) 86.53% compared to head (5c1b583) 86.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2655      +/-   ##
==========================================
+ Coverage   86.53%   86.73%   +0.20%     
==========================================
  Files         291      295       +4     
  Lines       16488    16753     +265     
  Branches     2118     2145      +27     
==========================================
+ Hits        14268    14531     +263     
  Misses       1819     1819              
- Partials      401      403       +2     
Impacted Files Coverage Δ
src/fides/api/custom_types.py 84.00% <84.00%> (ø)
.../ops/api/v1/endpoints/consent_request_endpoints.py 88.51% <100.00%> (+1.18%) ⬆️
...ction_configuration/connection_secrets_bigquery.py 100.00% <100.00%> (ø)
...nnection_configuration/connection_secrets_email.py 100.00% <100.00%> (ø)
src/fides/api/ops/schemas/drp_privacy_request.py 100.00% <100.00%> (ø)
src/fides/api/ops/schemas/messaging/messaging.py 97.79% <100.00%> (-0.05%) ⬇️
src/fides/api/ops/schemas/privacy_request.py 100.00% <100.00%> (ø)
src/fides/api/ops/schemas/redis_cache.py 100.00% <100.00%> (+10.52%) ⬆️
src/fides/api/ops/schemas/registration.py 100.00% <100.00%> (ø)

... and 23 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ThomasLaPiana
Copy link
Contributor Author

@RobertKeyser @daveqnet would you mind giving me some examples here of clearly dangerous/invalid user input so I can use them for test cases? I trust y'all here as the experts 😄 thank you!

@daveqnet
Copy link
Contributor

@RobertKeyser @daveqnet would you mind giving me some examples here of clearly dangerous/invalid user input so I can use them for test cases? I trust y'all here as the experts 😄 thank you!

Hmmm, it's a tricky one, as what constitutes dangerous input depends on what the input is being used for. Does the guidance here help: https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/ ?

I'll also try to provide you a few examples of some real injection vulnerabilities from non-fides penetration tests to help.

Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

Couple comments. But there's lots of other APIs to consider - here are a couple examples:

  • User.username, User.first_name, User.last_name
  • System.name, System.description (plus Dataset, DataCategory... all Resource models)
  • Organization has many string fields (name, description, controller.name...)
  • ...?

@pattisdr
Copy link
Contributor

If you're just looking for a list of our API endpoints that accept strings in the request body, I'd assume the majority do, too many to just list here.

Most of the ops schemas are here:
https://github.com/ethyca/fides/tree/main/src/fides/api/ops/schemas

If you're just trying to make a list to work from, you might write a script that goes through the contents of http://localhost:8080/openapi.json, for each request looks for the requestBody key and gets the schema from there - lots of recursion.

@ThomasLaPiana
Copy link
Contributor Author

based on the feedback here, it sounds like the safest way to go about things here is to update every string to use InputStr and see where that lands us...

Additionally, logging around when values get truncated would be helpful for debugging

@galvana
Copy link
Contributor

galvana commented Mar 3, 2023

@ThomasLaPiana I know the unsafe tests aren't being run in Github but let's make sure we run those to make sure we don't break any connector integrations with this change.

@ThomasLaPiana ThomasLaPiana changed the title Add broad server-side user input sanitization/validation Add Privacy Request Input Sanitization Mar 10, 2023
@ThomasLaPiana
Copy link
Contributor Author

ThomasLaPiana commented Mar 10, 2023

quick update: I can't test the specific fixes I made because I'm not sure how to use the local test env. It now requires privacy request configurations. Will message in slack and try to get this sorted

an update to the update: Adam got me pointed in the right direction, I wasn't leveraging the special .env properly

@ThomasLaPiana ThomasLaPiana added the run unsafe ci checks Runs fides-related CI checks that require sensitive credentials label Mar 13, 2023
@ThomasLaPiana ThomasLaPiana marked this pull request as ready for review March 14, 2023 13:39
@ThomasLaPiana
Copy link
Contributor Author

Both security issues confirmed closed. Cleaning up now and merging

@ThomasLaPiana
Copy link
Contributor Author

ThomasLaPiana commented Mar 15, 2023

Patch coverage is lacking but overall coverage is up, we're calling this one a win 🙃

Failing tests are known-failing, considering this good to merge

@ThomasLaPiana ThomasLaPiana merged commit f6cfa4a into main Mar 15, 2023
@ThomasLaPiana ThomasLaPiana deleted the ThomasLaPiana-add-user-validation-sanitization branch March 15, 2023 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run unsafe ci checks Runs fides-related CI checks that require sensitive credentials
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants