-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ruby policy for exposure of data category to third party (#210)
- Loading branch information
Showing
11 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
46 changes: 46 additions & 0 deletions
46
integration/policies/.snapshots/TestPolicies-sending_data_in_category_to_third_party
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
high: | ||
- policy_name: Third-party data category exposure | ||
policy_description: Sending data in category to third party | ||
line_number: 12 | ||
filename: testdata/ruby/sending_data_in_category_to_third_party.rb | ||
category_groups: | ||
- PHI | ||
- PII | ||
parent_line_number: 10 | ||
parent_content: |- | ||
Sentry::Breadcrumb.new( | ||
category: "auth", | ||
message: "Authenticated user #{user.email}", | ||
level: "info" | ||
) | ||
omit_parent: false | ||
- policy_name: Third-party data category exposure | ||
policy_description: Sending data in category to third party | ||
line_number: 18 | ||
filename: testdata/ruby/sending_data_in_category_to_third_party.rb | ||
category_groups: | ||
- PHI | ||
- PII | ||
parent_line_number: 16 | ||
parent_content: |- | ||
Sentry.init do |config| | ||
config.before_breadcrumb = lambda do |breadcrumb, hint| | ||
breadcrumb.message = "Authenticated user #{current_user.email}" | ||
breadcrumb | ||
end | ||
end | ||
omit_parent: false | ||
- policy_name: Third-party data category exposure | ||
policy_description: Sending data in category to third party | ||
line_number: 24 | ||
filename: testdata/ruby/sending_data_in_category_to_third_party.rb | ||
category_groups: | ||
- PHI | ||
- PII | ||
parent_line_number: 24 | ||
parent_content: 'Sentry.set_user(email: user.email)' | ||
omit_parent: false | ||
|
||
|
||
-- | ||
|
This file contains 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
24 changes: 24 additions & 0 deletions
24
integration/policies/testdata/ruby/sending_data_in_category_to_third_party.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Ruby third-party data send | ||
|
||
class User | ||
attr_accessor :email | ||
end | ||
|
||
current_user = user = User.new | ||
|
||
## Detected | ||
Sentry::Breadcrumb.new( | ||
category: "auth", | ||
message: "Authenticated user #{user.email}", | ||
level: "info" | ||
) | ||
|
||
Sentry.init do |config| | ||
config.before_breadcrumb = lambda do |breadcrumb, hint| | ||
breadcrumb.message = "Authenticated user #{current_user.email}" | ||
breadcrumb | ||
end | ||
end | ||
|
||
# https://docs.sentry.io/platforms/ruby/guides/rails/enriching-events/identify-user/ | ||
Sentry.set_user(email: user.email) |
This file contains 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
This file contains 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
22 changes: 22 additions & 0 deletions
22
pkg/commands/process/settings/policies/third_party_data_category.rego
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bearer.third_party_data_category | ||
|
||
import data.bearer.common | ||
|
||
import future.keywords | ||
|
||
policy_breach contains item if { | ||
some detector in input.dataflow.risks | ||
detector.detector_id == input.policy_id | ||
|
||
data_type = detector.data_types[_] | ||
|
||
location = data_type.locations[_] | ||
item := { | ||
"category_groups": data.bearer.common.groups_for_datatype(data_type), | ||
"severity": data.bearer.common.severity_of_datatype(data_type), | ||
"filename": location.filename, | ||
"line_number": location.line_number, | ||
"parent_line_number": location.parent.line_number, | ||
"parent_content": location.parent.content | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
pkg/detectors/custom/.snapshots/TestRubyThirdPartyDataSendJSON
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[ | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_ruby_third_party_data_send", | ||
"source": { | ||
"filename": "config.rb", | ||
"language": "Ruby", | ||
"language_type": "programming", | ||
"line_number": 6, | ||
"column_number": 39, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "user", | ||
"field_name": "email", | ||
"field_type": "", | ||
"field_type_simple": "unknown" | ||
} | ||
}, | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_ruby_third_party_data_send", | ||
"source": { | ||
"filename": "config.rb", | ||
"language": "Ruby", | ||
"language_type": "programming", | ||
"line_number": 12, | ||
"column_number": 61, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "current_user", | ||
"field_name": "email", | ||
"field_type": "", | ||
"field_type_simple": "unknown" | ||
} | ||
}, | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_ruby_third_party_data_send", | ||
"source": { | ||
"filename": "config.rb", | ||
"language": "Ruby", | ||
"language_type": "programming", | ||
"line_number": 18, | ||
"column_number": 29, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "user", | ||
"field_name": "email", | ||
"field_type": "", | ||
"field_type_simple": "unknown" | ||
} | ||
} | ||
] |
This file contains 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
16 changes: 16 additions & 0 deletions
16
pkg/detectors/custom/testdata/config/ruby_third_party_data_send.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
detect_ruby_third_party_data_send: | ||
type: "risk" | ||
patterns: | ||
- | | ||
Sentry::Breadcrumb.new(<$ARGUMENT>) | ||
- | | ||
Sentry.init do |config| | ||
config.before_breadcrumb = lambda do |breadcrumb, hint| | ||
breadcrumb.message = $ANYTHING | ||
breadcrumb | ||
end | ||
end | ||
- | | ||
Sentry.set_user(<$ARGUMENT>) | ||
languages: | ||
- ruby |
18 changes: 18 additions & 0 deletions
18
pkg/detectors/custom/testdata/ruby/third_party_data_send/config.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Ruby third-party data send | ||
|
||
## Detected | ||
Sentry::Breadcrumb.new( | ||
category: "auth", | ||
message: "Authenticated user #{user.email}", | ||
level: "info" | ||
) | ||
|
||
Sentry.init do |config| | ||
config.before_breadcrumb = lambda do |breadcrumb, hint| | ||
breadcrumb.message = "Authenticated user #{current_user.email}" | ||
breadcrumb | ||
end | ||
end | ||
|
||
# https://docs.sentry.io/platforms/ruby/guides/rails/enriching-events/identify-user/ | ||
Sentry.set_user(email: user.email) |