-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2952 from DataDog/appsec-automated-user-events-ch…
…eck-for-uuid-in-safe-mode [APPSEC-10361] Appsec automated user events check for UUID in safe mode
- Loading branch information
Showing
12 changed files
with
253 additions
and
86 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
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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module AppSec | ||
module Contrib | ||
module Devise | ||
# Class to extract event information from the resource | ||
class Event | ||
UUID_REGEX = /^\h{8}-\h{4}-\h{4}-\h{4}-\h{12}$/.freeze | ||
|
||
SAFE_MODE = 'safe' | ||
EXTENDED_MODE = 'extended' | ||
|
||
attr_reader :user_id | ||
|
||
def initialize(resource, mode) | ||
@resource = resource | ||
@mode = mode | ||
@user_id = nil | ||
@email = nil | ||
@username = nil | ||
|
||
extract if @resource | ||
end | ||
|
||
def to_h | ||
return @event if defined?(@event) | ||
|
||
@event = {} | ||
@event[:email] = @email if @email | ||
@event[:username] = @username if @username | ||
@event | ||
end | ||
|
||
private | ||
|
||
def extract | ||
@user_id = @resource.id | ||
|
||
case @mode | ||
when EXTENDED_MODE | ||
@email = @resource.email | ||
@username = @resource.username | ||
when SAFE_MODE | ||
@user_id = nil unless @user_id && @user_id.to_s =~ UUID_REGEX | ||
else | ||
Datadog.logger.warn( | ||
"Invalid automated user evenst mode: `#{@mode}`. "\ | ||
'Supported modes are: `safe` and `extended`.' | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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,26 @@ | ||
module Datadog | ||
module AppSec | ||
module Contrib | ||
module Devise | ||
class Event | ||
UUID_REGEX: ::Regexp | ||
|
||
SAFE_MODE: String | ||
|
||
EXTENDED_MODE: String | ||
|
||
attr_reader user_id: untyped | ||
|
||
def initialize: (Devise::Resource? resource, String mode) -> void | ||
|
||
|
||
def to_h: () -> Hash[Symbol, untyped] | ||
|
||
private | ||
|
||
def extract: () -> void | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.