Skip to content

Commit

Permalink
Apply some PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien committed Sep 3, 2024
1 parent a9c48b3 commit d77f60a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
11 changes: 7 additions & 4 deletions packages/datadog-instrumentations/src/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ function wrapQuery (query) {

if (abortController.signal.aborted) {
const error = abortController.signal.reason || new Error('Aborted')

// eslint-disable-next-line max-len
// Based on: https://github.com/brianc/node-postgres/blob/54eb0fa216aaccd727765641e7d1cf5da2bc483d/packages/pg/lib/client.js#L510
const reusingQuery = typeof pgQuery.submit === 'function'
const callback = arguments[arguments.length - 1]

finish(error)

if (reusingQuery) {
if (typeof callback === 'function') {
pgQuery.callback = pgQuery.callback || callback
if (!pgQuery.callback && typeof callback === 'function') {
pgQuery.callback = callback
}

if (pgQuery.callback) {
Expand All @@ -96,9 +99,9 @@ function wrapQuery (query) {
callback(error)

return
} else {
return Promise.reject(error)
}

return Promise.reject(error)
}

arguments[0] = pgQuery
Expand Down
10 changes: 1 addition & 9 deletions packages/dd-trace/src/appsec/rasp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
const web = require('../../plugins/util/web')
const { setUncaughtExceptionCaptureCallbackStart } = require('../channels')
const { block } = require('../blocking')
const log = require('../../log')
const ssrf = require('./ssrf')
const sqli = require('./sql_injection')

const { setAbortOnUncaughtException, DatadogRaspAbortError } = require('./utils')
const { DatadogRaspAbortError } = require('./utils')

function removeAllListeners (emitter, event) {
const listeners = emitter.listeners(event)
Expand Down Expand Up @@ -88,13 +87,6 @@ function enable (config) {
sqli.enable(config)

process.on('uncaughtExceptionMonitor', handleUncaughtExceptionMonitor)

const abortOnUncaughtException = process.execArgv?.includes('--abort-on-uncaught-exception')
setAbortOnUncaughtException(abortOnUncaughtException)

if (abortOnUncaughtException) {
log.warn('The --abort-on-uncaught-exception flag is enabled. The RASP module will not block operations.')
}
}

function disable () {
Expand Down
3 changes: 1 addition & 2 deletions packages/dd-trace/src/appsec/rasp/sql_injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function analyzePgSqlInjection (ctx) {
const store = storage.getStore()
if (!store) return

const { raspSqlAnalyzed, req } = store
const { raspSqlAnalyzed, req, res } = store

if (!req || raspSqlAnalyzed) return

Expand All @@ -40,7 +40,6 @@ function analyzePgSqlInjection (ctx) {

const result = waf.run({ persistent }, req, RULE_TYPES.SQL_INJECTION)

const res = store?.res
handleResult(result, req, res, ctx.abortController, config)
}

Expand Down
12 changes: 6 additions & 6 deletions packages/dd-trace/src/appsec/rasp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
const web = require('../../plugins/util/web')
const { reportStackTrace } = require('../stack_trace')
const { getBlockingAction } = require('../blocking')
const log = require('../../log')

let abortOnUncaughtException = false
const abortOnUncaughtException = process.execArgv?.includes('--abort-on-uncaught-exception')

if (abortOnUncaughtException) {
log.warn('The --abort-on-uncaught-exception flag is enabled. The RASP module will not block operations.')
}

const RULE_TYPES = {
SSRF: 'ssrf',
Expand Down Expand Up @@ -55,13 +60,8 @@ function handleResult (actions, req, res, abortController, config) {
}
}

function setAbortOnUncaughtException (newAbortOnUncaughtException) {
abortOnUncaughtException = newAbortOnUncaughtException
}

module.exports = {
handleResult,
setAbortOnUncaughtException,
RULE_TYPES,
DatadogRaspAbortError
}

0 comments on commit d77f60a

Please sign in to comment.