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

fix: sentry pii #615

Merged
merged 1 commit into from
Feb 19, 2025
Merged

fix: sentry pii #615

merged 1 commit into from
Feb 19, 2025

Conversation

ruuushhh
Copy link
Contributor

@ruuushhh ruuushhh commented Feb 19, 2025

Description

fix: pii

Clickup

https://app.clickup.com/t/86cxygv7h

Summary by CodeRabbit

  • New Features

    • Enhanced error monitoring now masks sensitive user information in error reports. Personally identifiable data, headers, and request details are automatically filtered out by default, bolstering data privacy and security.
  • Refactor

    • Streamlined the processing of error events and diagnostic breadcrumbs, ensuring clearer, more consistent handling of sensitive information across error monitoring workflows.

@ruuushhh ruuushhh self-assigned this Feb 19, 2025
@github-actions github-actions bot added the size/M Medium PR label Feb 19, 2025
Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

This change updates the Sentry integration in fyle_intacct_api/sentry.py to improve sensitive data handling. A new class constant SENSITIVE_FIELDS is introduced alongside a static helper _sanitize_dict for recursive sanitization. The init method now defaults to not sending personally identifiable information. Additionally, the before_send method has been updated with explicit type annotations and enhanced logic to filter sensitive request headers, extra data, and user information. A new before_breadcrumb method is added, applying similar sanitization to breadcrumb entries.

Changes

File Change Summary
fyle_intacct_api/sentry.py - Constant Added: SENSITIVE_FIELDS set of sensitive keys
- Method Added: Static _sanitize_dict to recursively filter sensitive data
- Modification: init now sets send_default_pii to False
- Update: before_send method with typed parameters and filtering logic
- Method Added: before_breadcrumb for breadcrumb sanitization

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Sentry
    participant _sanitize_dict
    participant SentryBreadcrumb

    Client->>Sentry: Send event data
    Sentry->>_sanitize_dict: Sanitize request and extra fields
    _sanitize_dict-->>Sentry: Return sanitized data
    Sentry->>Client: Return sanitized event

    Client->>Sentry: Send breadcrumb data
    Sentry->>SentryBreadcrumb: Process breadcrumb
    SentryBreadcrumb-->>Sentry: Return sanitized breadcrumb
    Sentry->>Client: Return sanitized breadcrumb
Loading

Suggested reviewers

  • Ashutosh619-sudo

Poem

I’m a hopping little rabbit,
Skipping through lines of secure code,
Filtering out secrets silently,
Ensuring data’s in safe mode.
With a twitch of my whiskers, I cheer—
Code secured, and worries cleared!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Coverage

Coverage Report
FileStmtsMissCoverMissing
apps
   exceptions.py431467%27, 33, 39–44, 50, 56–61, 67, 73, 79–80, 92–94
apps/fyle
   actions.py700100% 
   constants.py10100% 
   helpers.py2253584%184–216, 258–264, 440–444, 469–473, 507, 514–517, 520–521
   models.py3202293%299–301, 305–307, 311–313, 317–319, 323–325, 329–331, 392, 493–526, 565
   queue.py180100% 
   serializers.py410100% 
   signals.py180100% 
   tasks.py1694971%149–158, 190–195, 198–203, 206–211, 231–255, 278, 312–343
   views.py1821592%92–99, 267, 345–346, 379–380, 405–409, 502–506
apps/internal
   actions.py180100% 
   views.py40198%37
apps/mappings
   constants.py10100% 
   exceptions.py60395%62–64
   helpers.py20575%45–55
   models.py700100% 
   serializers.py100100% 
   signals.py82791%84–86, 121, 167–172
   tasks.py991288%112–119, 238, 241, 244, 249–253
   utils.py360100% 
   views.py51296%35–36
apps/mappings/imports
   schedules.py150100% 
apps/mappings/imports/modules
   base.py153299%122, 345
   categories.py64592%112–113, 123, 125, 157
   cost_centers.py55591%91–92, 103, 105, 139
   expense_custom_fields.py69396%60–65
   merchants.py260100% 
   projects.py61493%94–95, 111, 147
   tax_groups.py150100% 
apps/sage_intacct
   dependent_fields.py1921990%266–269, 292–295, 297–298, 300–301, 303–304, 308–310, 398–400
   helpers.py400100% 
   models.py7622397%67–68, 301, 342, 420, 482, 488, 523, 685, 1013–1016, 1195–1214
   queue.py155895%74–75, 141–142, 196–197, 252–253
   serializers.py310100% 
   tasks.py8559589%151, 187–188, 192–195, 197, 200, 250, 284–285, 424, 430, 438, 622–623, 669–670, 816–817, 957–958, 1096–1097, 1276–1285, 1327–1350, 1468–1472, 1534–1536, 1601–1611, 1614, 1627–1658, 1669–1671, 1685–1688
   utils.py6823994%147, 377–378, 383, 441–442, 512–516, 620, 843, 1277–1295, 1428–1432, 1460–1464, 1492–1496, 1569–1573, 1593, 1602, 1611, 1620–1621, 1657–1665, 1670, 1822
   views.py98595%178–179, 185–186, 241
apps/sage_intacct/errors
   errors.py20100% 
   helpers.py26196%73
apps/tasks
   models.py500100% 
   serializers.py60100% 
   views.py430100% 
apps/users
   helpers.py120100% 
   models.py530100% 
   views.py240100% 
apps/workspaces
   actions.py45296%41, 125
   models.py1070100% 
   permissions.py34974%33, 59–67
   serializers.py39197%53
   signals.py24196%55
   tasks.py109694%160–162, 178, 208–209
   utils.py9544%15–24
   views.py214797%68–71, 104, 428–429
apps/workspaces/apis/advanced_settings
   serializers.py78396%245, 248, 251
   triggers.py100100% 
   views.py110100% 
apps/workspaces/apis/errors
   serializers.py200100% 
   views.py150100% 
apps/workspaces/apis/export_settings
   serializers.py93397%249, 252, 255
   triggers.py210100% 
   views.py110100% 
apps/workspaces/apis/import_settings
   serializers.py121695%239, 242, 270, 273–274, 282
   triggers.py31197%29
   views.py330100% 
TOTAL608841893% 

Tests Skipped Failures Errors Time
286 0 💤 0 ❌ 0 🔥 41.181s ⏱️

Copy link

Coverage

Coverage Report
FileStmtsMissCoverMissing
apps
   exceptions.py431467%27, 33, 39–44, 50, 56–61, 67, 73, 79–80, 92–94
apps/fyle
   actions.py700100% 
   constants.py10100% 
   helpers.py2253584%184–216, 258–264, 440–444, 469–473, 507, 514–517, 520–521
   models.py3202293%299–301, 305–307, 311–313, 317–319, 323–325, 329–331, 392, 493–526, 565
   queue.py180100% 
   serializers.py410100% 
   signals.py180100% 
   tasks.py1694971%149–158, 190–195, 198–203, 206–211, 231–255, 278, 312–343
   views.py1821592%92–99, 267, 345–346, 379–380, 405–409, 502–506
apps/internal
   actions.py180100% 
   views.py40198%37
apps/mappings
   constants.py10100% 
   exceptions.py60395%62–64
   helpers.py20575%45–55
   models.py700100% 
   serializers.py100100% 
   signals.py82791%84–86, 121, 167–172
   tasks.py991288%112–119, 238, 241, 244, 249–253
   utils.py360100% 
   views.py51296%35–36
apps/mappings/imports
   schedules.py150100% 
apps/mappings/imports/modules
   base.py153299%122, 345
   categories.py64592%112–113, 123, 125, 157
   cost_centers.py55591%91–92, 103, 105, 139
   expense_custom_fields.py69396%60–65
   merchants.py260100% 
   projects.py61493%94–95, 111, 147
   tax_groups.py150100% 
apps/sage_intacct
   dependent_fields.py1921990%266–269, 292–295, 297–298, 300–301, 303–304, 308–310, 398–400
   helpers.py400100% 
   models.py7622397%67–68, 301, 342, 420, 482, 488, 523, 685, 1013–1016, 1195–1214
   queue.py155895%74–75, 141–142, 196–197, 252–253
   serializers.py310100% 
   tasks.py8559589%151, 187–188, 192–195, 197, 200, 250, 284–285, 424, 430, 438, 622–623, 669–670, 816–817, 957–958, 1096–1097, 1276–1285, 1327–1350, 1468–1472, 1534–1536, 1601–1611, 1614, 1627–1658, 1669–1671, 1685–1688
   utils.py6823994%147, 377–378, 383, 441–442, 512–516, 620, 843, 1277–1295, 1428–1432, 1460–1464, 1492–1496, 1569–1573, 1593, 1602, 1611, 1620–1621, 1657–1665, 1670, 1822
   views.py98595%178–179, 185–186, 241
apps/sage_intacct/errors
   errors.py20100% 
   helpers.py26196%73
apps/tasks
   models.py500100% 
   serializers.py60100% 
   views.py430100% 
apps/users
   helpers.py120100% 
   models.py530100% 
   views.py240100% 
apps/workspaces
   actions.py45296%41, 125
   models.py1070100% 
   permissions.py34974%33, 59–67
   serializers.py39197%53
   signals.py24196%55
   tasks.py109694%160–162, 178, 208–209
   utils.py9544%15–24
   views.py214797%68–71, 104, 428–429
apps/workspaces/apis/advanced_settings
   serializers.py78396%245, 248, 251
   triggers.py100100% 
   views.py110100% 
apps/workspaces/apis/errors
   serializers.py200100% 
   views.py150100% 
apps/workspaces/apis/export_settings
   serializers.py93397%249, 252, 255
   triggers.py210100% 
   views.py110100% 
apps/workspaces/apis/import_settings
   serializers.py121695%239, 242, 270, 273–274, 282
   triggers.py31197%29
   views.py330100% 
TOTAL608841893% 

Tests Skipped Failures Errors Time
286 0 💤 0 ❌ 0 🔥 41.201s ⏱️

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
fyle_intacct_api/sentry.py (3)

10-15: Centralize sensitive fields.

Defining a single source of truth for sensitive fields is a solid approach. Consider auditing the codebase to ensure that all potential PII or security-sensitive fields (e.g., 'token') are consistently included here if necessary.


16-39: Robust recursive sanitization.

Your _sanitize_dict function correctly handles nested dicts and lists. However, cyclical references in the data could cause infinite recursion. If you expect potentially self-referential data structures, consider adding a visited-set check to avoid recursion errors.

 def _sanitize_dict(data: Dict[str, Any], visited=None) -> Dict[str, Any]:
     if visited is None:
+        visited = set()
+    if id(data) in visited:
+        return {}
+    visited.add(id(data))

     sanitized = {}
     ...

67-76: Combine conditional checks for brevity (static analysis hint).

To streamline exception checks, you can merge the two branches into a single condition:

         if 'exc_info' in hint:
             exc_type, exc_value, tb = hint['exc_info']
-            if isinstance(exc_value, gevent.GreenletExit):
-                return None
-            elif getattr(exc_value, 'args', [None])[0] in ['Error: 502']:
+            if isinstance(exc_value, gevent.GreenletExit) or getattr(exc_value, 'args', [None])[0] in ['Error: 502']:
                 return None
🧰 Tools
🪛 Ruff (0.8.2)

72-75: Combine if branches using logical or operator

Combine if branches

(SIM114)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3839ee and 480d09b.

📒 Files selected for processing (1)
  • fyle_intacct_api/sentry.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
fyle_intacct_api/sentry.py

72-75: Combine if branches using logical or operator

Combine if branches

(SIM114)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: pytest
  • GitHub Check: pytest
🔇 Additional comments (5)
fyle_intacct_api/sentry.py (5)

2-4: Imports look good.

These additions are necessary for type annotations and handling with gevent. No concerns here.


44-47: Sentry initialization aligns with PII concerns.

Turning off default PII and specifying in-app folders properly addresses privacy requirements. This matches the PR objective to reduce exposure of sensitive information in Sentry.

Also applies to: 50-51, 53-63


78-91: Request headers and body sanitization.

Filtering sensitive headers and recursively sanitizing request data is correct and prevents accidental PII leakage. Nicely done.


92-103: Strict user field filtering.

Restricting the user object to only contain the 'id' field effectively curtails PII from being transmitted. This is consistent with the privacy goals of the PR.


106-117: Breadcrumb filtering.

Dropping breadcrumbs for certain categories and sanitizing any embedded data aligns well with the product's PII-safe stance. This feature is suitably implemented.

@ruuushhh ruuushhh merged commit 2afcfb0 into master Feb 19, 2025
5 checks passed
ruuushhh added a commit that referenced this pull request Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants