Skip to content

Commit

Permalink
Merge pull request #2909 from DataDog/maximo/consistent-query-string-…
Browse files Browse the repository at this point in the history
…regexp-config

Fixing DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP Empty Value Behavior
  • Loading branch information
link04 authored Nov 5, 2024
2 parents 5a693b6 + d77bcda commit a1ec6f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/DDTrace/Util/Normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ private static function generateFilteredPostFields($postKey, $postVal, array $wh
// Concatenate the postkey and postval into '<postkey>=<postval>'
$postField = "$postKey=$postVal";

// Match it with the regex to redact if needed
// Match it with the regex to redact if needed and regex is not empty
$obfuscationRegex = \ini_get('datadog.trace.obfuscation_query_string_regexp');
$obfuscationRegex = '(' . $obfuscationRegex . ')';
if (preg_match($obfuscationRegex, $postField)) {
if ($obfuscationRegex != "" && preg_match('(' . $obfuscationRegex . ')', $postField)) {
return [$postKey => '<redacted>'];
} else {
return [$postKey => $postVal];
Expand Down
23 changes: 23 additions & 0 deletions tests/ext/root_span_url_with_query_params_obfuscation_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Root span with http.url and unobfuscated query string with empty regex
--INI--
datadog.trace.obfuscation_query_string_regexp=
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
HTTPS=off
HTTP_HOST=localhost:9999
SCRIPT_NAME=/foo.php
REQUEST_URI=/users?application_key=123
QUERY_STRING=application_key=123
METHOD=GET
--GET--
application_key=123
--FILE--
<?php
DDTrace\start_span();
DDTrace\close_span();
$spans = dd_trace_serialize_closed_spans();
var_dump($spans[0]['meta']["http.url"]);
?>
--EXPECT--
string(48) "https://localhost:9999/users?application_key=123"
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ zend_string *zai_filter_query_string(zai_str queryString, zend_array *whitelist,
zend_hash_get_current_key(whitelist, &str, &numkey);
if (zend_string_equals_literal(str, "*")) {
zend_string *qs = zend_string_init(queryString.ptr, queryString.len, 0);
if (pattern) {
if (pattern && ZSTR_LEN(pattern)) {
zend_string *replacement = zend_string_init(ZEND_STRL("<redacted>"), 0);

smart_str regex = {0};
Expand Down

0 comments on commit a1ec6f8

Please sign in to comment.