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

Fixing DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP Empty Value Behavior #2909

Merged
merged 9 commits into from
Nov 5, 2024
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
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 (ZSTR_LEN(pattern)) {
bwoebi marked this conversation as resolved.
Show resolved Hide resolved
zend_string *replacement = zend_string_init(ZEND_STRL("<redacted>"), 0);

smart_str regex = {0};
Expand Down
Loading