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

[APPSEC-10361] Appsec automated user events check for UUID in safe mode #2952

Merged

Conversation

GustavoCaso
Copy link
Member

@GustavoCaso GustavoCaso commented Jul 6, 2023

What does this PR do?

For safe automated user tracking events, we want to reduce the possibility of reporting PII information as much as possible. The RFC states that we could report any integer that we know 100% has been autogenerated, we could make the assumption that every ID or UUID coming from Rails is autogenerated, but since we can not be 100% sure, in safe mode we only report IDs if they are UUID.

This PR extracts the logic of gathering event information into a new module, Devise::EventInformation.

Motivation

Additional Notes

I realised the devise specs were not running in CI 🤦

The second commit enables the devise integration specs in CI 0b9c43c.

How to test the change?

CI

@github-actions github-actions bot added appsec Application Security monitoring product integrations Involves tracing integrations labels Jul 6, 2023
@GustavoCaso GustavoCaso changed the title Appsec automated user events check for UUID in safe mode [APPSEC-10361] Appsec automated user events check for UUID in safe mode Jul 6, 2023
@GustavoCaso GustavoCaso marked this pull request as ready for review July 6, 2023 13:21
@GustavoCaso GustavoCaso requested review from a team and lloeki July 6, 2023 13:21
Copy link
Member

@lloeki lloeki left a comment

Choose a reason for hiding this comment

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

Overall LGTM, left a few notes.

event[:email] = resource_email if resource_email
event[:username] = resource_username if resource_username
when SAFE_MODE
event[:id] = resource_id if resource_id && resource_id.to_s =~ UUID_REGEX
Copy link
Member

Choose a reason for hiding this comment

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

Certainly not for this PR but there is an opportunity here to define matchers (e.g as procs) and iterate over them, in order to easily extend the list of known safe bits of info.

Copy link
Member

Choose a reason for hiding this comment

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

Also, for my understanding, wasn't there a thing specified where known unsafe bits of info would get hashed to pseudonymous information?

Copy link
Member Author

Choose a reason for hiding this comment

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

Certainly not for this PR but there is an opportunity here to define matchers (e.g as procs) and iterate over them, in order to easily extend the list of known safe bits of info.

Noted. I don't think there will be more mode in the future, but if the list where to grow I happy to extract the logic into matchers

Copy link
Member Author

@GustavoCaso GustavoCaso Jul 6, 2023

Choose a reason for hiding this comment

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

Also, for my understanding, wasn't there a thing specified where known unsafe bits of info would get hashed to pseudonymous information?

In the end, for simplify, we decided not to do it on the first iteration. So in safe mode, we only report ID if we are sure they are UUID. If the customers want to report more information they would need to change the mode to extended. Which reports ID no matter the shape

module Contrib
module Devise
# Module to extract event information from the resource
module EventInformation
Copy link
Member

Choose a reason for hiding this comment

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

WDYT of the class name simply be Devise::Event?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good

SAFE_MODE = 'safe'
EXTENDED_MODE = 'extended'

def self.extract(resource, mode)
Copy link
Member

Choose a reason for hiding this comment

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

WDYT of this being .new (or #initialize)?

@GustavoCaso GustavoCaso force-pushed the appsec-automated-user-events-check-for-uuid-in-safe-mode branch from 5d8013e to cfe7763 Compare July 7, 2023 13:04
@codecov-commenter
Copy link

Codecov Report

Merging #2952 (cfe7763) into master (e195974) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2952      +/-   ##
==========================================
+ Coverage   97.96%   98.06%   +0.09%     
==========================================
  Files        1287     1293       +6     
  Lines       71018    71438     +420     
  Branches     3285     3289       +4     
==========================================
+ Hits        69574    70055     +481     
+ Misses       1444     1383      -61     
Impacted Files Coverage Δ
lib/datadog/appsec/contrib/devise/patcher.rb 69.56% <ø> (-2.44%) ⬇️
lib/datadog/appsec/contrib/devise/event.rb 100.00% <100.00%> (ø)
...ec/contrib/devise/patcher/authenticatable_patch.rb 100.00% <100.00%> (+75.67%) ⬆️
...ib/devise/patcher/registration_controller_patch.rb 100.00% <100.00%> (+68.96%) ⬆️
lib/datadog/kit/appsec/events.rb 100.00% <100.00%> (ø)
spec/datadog/appsec/contrib/devise/event_spec.rb 100.00% <100.00%> (ø)
...ntrib/devise/patcher/authenticatable_patch_spec.rb 100.00% <100.00%> (ø)
...vise/patcher/registration_controller_patch_spec.rb 99.00% <100.00%> (ø)
...pec/datadog/appsec/contrib/devise/tracking_spec.rb 100.00% <100.00%> (ø)
spec/datadog/kit/appsec/events_spec.rb 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@GustavoCaso GustavoCaso merged commit 3438aab into master Jul 7, 2023
@GustavoCaso GustavoCaso deleted the appsec-automated-user-events-check-for-uuid-in-safe-mode branch July 7, 2023 13:37
@github-actions github-actions bot added this to the 1.13.0 milestone Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appsec Application Security monitoring product integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants