-
Notifications
You must be signed in to change notification settings - Fork 309
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
Automatic userID tracking and blocking #4670
Draft
simon-id
wants to merge
100
commits into
master
Choose a base branch
from
automatic_userid_blocking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 77 commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
81f6ab5
instrument passport
simon-id 023828c
lint
simon-id 98090fb
update config
simon-id 5cc7274
add new RC capability
simon-id 3343878
Merge branch 'master' into new_user_collection
simon-id 4e127de
add RC handler
simon-id b4daf8f
fix require path
simon-id 5f85b8e
add setCollectionMode()
simon-id 1b074ad
use setCollectionMode() in appsec index
simon-id cbc8cf3
DRY up passport strategies instrumentation
simon-id 729241d
simplify passport strategies instrumentations
simon-id 6ffc21f
simplify instrumentation
simon-id 4433baa
note for later
simon-id cf39858
add blocking to login
simon-id 2da5bef
Merge branch 'master' into new_user_collection
simon-id d8bed47
add abortController in listener
simon-id 5105006
cleanup
simon-id 65c680b
update typings
simon-id 23f965d
cleanup
simon-id b5b336a
RC config update
simon-id 53a7791
push everything
simon-id 2b7d2e6
simplify passport strategies instrumentation
simon-id 24c2828
fixes
simon-id cdb89f6
simplify code
simon-id 32edfae
cleanup
simon-id 50b3605
revert some changes
simon-id b5aa0d4
delete passport.js
simon-id 1f30a3c
Update packages/datadog-instrumentations/src/passport-utils.js
simon-id 9fee2bc
update verify subscriber
simon-id be3115a
rollback config changes
simon-id 38b4419
fix config
simon-id 40c9df1
add blocking for passport strategies
simon-id e34bb72
update typings and docs
simon-id d255702
update appsec index
simon-id b6d4584
update RC
simon-id 75782f9
Merge branch 'master' into new_user_collection
simon-id 4ff8379
push some stuff
simon-id be473e6
push some stuff
simon-id 4a566a8
cleanup
simon-id 882bc8b
cleanup
simon-id d4345ef
add new usr.login waf address
simon-id be4a06c
commit some stuff
simon-id f129890
cleanup
simon-id 58897c8
Merge branch 'new_user_collection' into automatic_userid_blocking
simon-id cceac23
cleanup
simon-id 654d260
add comment for later
simon-id 066da87
add some ideas
simon-id da9b270
cleanup
simon-id 01c8240
aaaaa
simon-id cc86e3a
pass abort controller for blocking
simon-id 69d12a9
push some notes
simon-id ce604c1
change config default
simon-id 56c30e8
handle duplicate RC confs for auto_user_instrum.mode
simon-id 1d3773a
refactor sdk/track_event.js to only be used by the SDK
simon-id a9f5c01
Merge branch 'new_user_collection' into automatic_userid_blocking
simon-id a72695f
push some stuff
simon-id 91a59db
remove some comments
simon-id faea3aa
pass login to WAF in SDK login success event
simon-id fe70c84
add comments
simon-id e32f78e
add framework name to passport strategy instrum
simon-id 806ab23
add framework name and waf handleResults() to onPassportVerify()
simon-id 69be031
Merge branch 'master' into new_user_collection
simon-id 1e1bb47
finally commit trackLogin()
simon-id 8eac055
fix tag override condition
simon-id a444cfe
add telemetry function
simon-id 187b42f
Merge branch 'master' into new_user_collection
simon-id 72a4a8b
Merge branch 'master' into new_user_collection
simon-id 9fa94f6
move user_tracking into a file instead of a subfolder
simon-id d51e434
Merge branch 'master' into new_user_collection
simon-id 8b22248
remove changes
simon-id 25abd50
temp revert changes
simon-id 52a0601
temp revert changes
simon-id b72ce34
Merge branch 'new_user_collection' into automatic_userid_blocking
simon-id 5a10fc0
fix conflict
simon-id 9869c4b
wrong file
simon-id 76e2e65
add some stuff
simon-id 80ae693
push some stuff
simon-id 7e3374d
Use addresses enum instead of hardcoded business logic events
simon-id c099a2a
Update default value of collection mode in typings
simon-id 96cb722
Add string check in getUserId()
simon-id 0a347e8
Merge branch 'master' into new_user_collection
simon-id 85ad6f2
fix existing RC tests
simon-id 70dcbab
add tests for RC collection mode
simon-id ff72271
fix env var ordering
simon-id 7338bd6
cleanup track_event.spec.js
simon-id b71ed06
do not export or test trackEvent()
simon-id 166bc23
update test, cleanup, and add missing coverage
simon-id a93b79a
change ordering of code to match tests
simon-id a83c4fb
delete passport-utils tests because it's useless
simon-id 6cf7ef2
fix test to correctly use passReqToCallback
simon-id 29c0d62
update passport-local tests
simon-id a6211b2
Merge branch 'new_user_collection' into automatic_userid_blocking
simon-id afafb8a
update tests for passpot-http
simon-id 956cb9b
allow empty login strings
simon-id 62ae42b
update TS tests
simon-id 375f688
update telemetry tests
simon-id 79a7ff5
Merge branch 'new_user_collection' into automatic_userid_blocking
simon-id b47e44a
Merge branch 'master' into automatic_userid_blocking
simon-id 5a0ee2e
push stuff
simon-id 775bf9a
remove session id support
simon-id File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,22 +1,10 @@ | ||
'use strict' | ||
|
||
const shimmer = require('../../datadog-shimmer') | ||
const { addHook } = require('./helpers/instrument') | ||
const { wrapVerify } = require('./passport-utils') | ||
const { strategyHook } = require('./passport-utils') | ||
|
||
addHook({ | ||
name: 'passport-http', | ||
file: 'lib/passport-http/strategies/basic.js', | ||
versions: ['>=0.3.0'] | ||
}, BasicStrategy => { | ||
return shimmer.wrapFunction(BasicStrategy, BasicStrategy => function () { | ||
const type = 'http' | ||
|
||
if (typeof arguments[0] === 'function') { | ||
arguments[0] = wrapVerify(arguments[0], false, type) | ||
} else { | ||
arguments[1] = wrapVerify(arguments[1], (arguments[0] && arguments[0].passReqToCallback), type) | ||
} | ||
return BasicStrategy.apply(this, arguments) | ||
}) | ||
}) | ||
}, strategyHook) |
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 |
---|---|---|
@@ -1,22 +1,10 @@ | ||
'use strict' | ||
|
||
const shimmer = require('../../datadog-shimmer') | ||
const { addHook } = require('./helpers/instrument') | ||
const { wrapVerify } = require('./passport-utils') | ||
const { strategyHook } = require('./passport-utils') | ||
|
||
addHook({ | ||
name: 'passport-local', | ||
file: 'lib/strategy.js', | ||
versions: ['>=1.0.0'] | ||
}, Strategy => { | ||
return shimmer.wrapFunction(Strategy, Strategy => function () { | ||
const type = 'local' | ||
|
||
if (typeof arguments[0] === 'function') { | ||
arguments[0] = wrapVerify(arguments[0], false, type) | ||
} else { | ||
arguments[1] = wrapVerify(arguments[1], (arguments[0] && arguments[0].passReqToCallback), type) | ||
} | ||
return Strategy.apply(this, arguments) | ||
}) | ||
}) | ||
}, strategyHook) |
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,87 @@ | ||
'use strict' | ||
|
||
const shimmer = require('../../datadog-shimmer') | ||
const { channel, addHook } = require('./helpers/instrument') | ||
|
||
/* TODO: test with: | ||
passport-jwt JWTs | ||
can be used both for login events, or as a session, that complicates things it think | ||
maybe instrument this lib directly, and ofc only send the events after it was verified | ||
@nestjs/passport | ||
pasport-local | ||
passport-oauth2 | ||
passport-google-oauth20 | ||
passport-custom | ||
passport-http | ||
passport-http-bearer | ||
koa-passport | ||
*/ | ||
|
||
const onPassportDeserializeUserChannel = channel('datadog:passport:deserializeUser:finish') | ||
|
||
function wrapDone (req, done) { | ||
// eslint-disable-next-line n/handle-callback-err | ||
return function wrappedDone (err, user) { | ||
if (user) { | ||
const abortController = new AbortController() | ||
|
||
// express-session middleware sets req.sessionID, it's required to use passport sessions anyway so might as well use it ? | ||
// what if session IDs are using rolling sessions or always changing or something idk ? | ||
onPassportDeserializeUserChannel.publish({ req, user, sessionId: req.sessionID, abortController }) | ||
|
||
if (abortController.signal.aborted) return | ||
} | ||
|
||
return done.apply(this, arguments) | ||
} | ||
} | ||
|
||
function wrapDeserializeUser (deserializeUser) { | ||
return function wrappedDeserializeUser (fn, req, done) { | ||
if (typeof req === 'function') { | ||
done = req | ||
// req = storage.getStore().get('req') | ||
arguments[1] = wrapDone(done) | ||
} else { | ||
arguments[2] = wrapDone(done) | ||
} | ||
|
||
return deserializeUser.apply(this, arguments) | ||
} | ||
} | ||
|
||
|
||
const { block } = require('../../dd-trace/src/appsec/blocking') | ||
const { getRootSpan } = require('../../dd-trace/src/appsec/sdk/utils') | ||
|
||
addHook({ | ||
name: 'passport', | ||
file: 'lib/authenticator.js', | ||
versions: ['>=0.3.0'] // TODO | ||
}, Authenticator => { | ||
shimmer.wrap(Authenticator.prototype, 'deserializeUser', wrapDeserializeUser) | ||
|
||
shimmer.wrap(Authenticator.prototype, 'authenticate', function wrapAuthenticate (authenticate) { | ||
return function wrappedAuthenticate (name) { | ||
const middleware = authenticate.apply(this, arguments) | ||
|
||
const strategy = this._strategy(name) | ||
|
||
strategy._verify | ||
|
||
return function wrappedMiddleware (req, res, next) { | ||
return middleware(req, res, function wrappedNext (err) { | ||
console.log('NEW', req.user) | ||
if (req.user?.name === 'bitch') { | ||
|
||
return block(req, res, getRootSpan(global._ddtrace)) | ||
} | ||
|
||
return next.apply(this, arguments) | ||
}) | ||
} | ||
} | ||
}) | ||
|
||
return Authenticator | ||
}) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.session can be used to know if it's login or session or not ?