-
Notifications
You must be signed in to change notification settings - Fork 182
Implement normalised http routes #4101
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
base: master
Are you sure you want to change the base?
Changes from all commits
7a82720
d252489
3f60b3b
f330003
9ba27a5
17aa400
7b7f971
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,11 +75,16 @@ static function ($errorMiddleware, $self, $args) use ($rootSpan, $integration) { | |
| null, | ||
| static function ($router, $scope, $args, $return) use ($rootSpan) { | ||
| /** @var \Slim\Interfaces\RouteInterface $return */ | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $return->getPattern(); | ||
| $pattern = $return->getPattern(); | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $pattern; | ||
| $normalizedRoute = \DDTrace\Util\RouteNormalizer::normalizeFromSlim($pattern); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For Slim 3 routes containing optional sections, this call always supplies an empty matched-parameter array, and only the Slim 4 controller path later refines the result. Thus a request matching Useful? React with 👍 / 👎. |
||
| if ($normalizedRoute !== null) { | ||
| $rootSpan->meta[Tag::APPSEC_NORMALIZED_ROUTE] = $normalizedRoute; | ||
| } | ||
|
|
||
| if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) { | ||
| $rootSpan->resource = | ||
| $_SERVER['REQUEST_METHOD'] . ' ' . ($return->getName() ?: $return->getPattern()); | ||
| $_SERVER['REQUEST_METHOD'] . ' ' . ($return->getName() ?: $pattern); | ||
| } | ||
| } | ||
| ); | ||
|
|
@@ -92,7 +97,12 @@ static function ($router, $scope, $args, $return) use ($rootSpan) { | |
| static function ($router, $scope, $args, $return) use ($rootSpan) { | ||
| /** @var \Slim\Interfaces\RouteInterface $route */ | ||
| $route = $return; | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $route->getPattern(); | ||
| $pattern = $route->getPattern(); | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $pattern; | ||
| $normalizedRoute = \DDTrace\Util\RouteNormalizer::normalizeFromSlim($pattern); | ||
| if ($normalizedRoute !== null) { | ||
| $rootSpan->meta[Tag::APPSEC_NORMALIZED_ROUTE] = $normalizedRoute; | ||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
@@ -131,6 +141,15 @@ static function ($router, $scope, $args, $return) use ($rootSpan) { | |
| $span->meta['slim.route.name'] = $routeName; | ||
| $rootSpan->meta['slim.route.name'] = $routeName; | ||
| } | ||
| // Refine normalized route now that matched params are available | ||
| $matchedParams = method_exists($route, 'getArguments') ? ($route->getArguments() ?? []) : []; | ||
| $pattern = isset($rootSpan->meta[Tag::HTTP_ROUTE]) ? $rootSpan->meta[Tag::HTTP_ROUTE] : ''; | ||
| if ($pattern !== '') { | ||
| $normalizedRoute = \DDTrace\Util\RouteNormalizer::normalizeFromSlim($pattern, $matchedParams); | ||
| if ($normalizedRoute !== null) { | ||
| $rootSpan->meta[Tag::APPSEC_NORMALIZED_ROUTE] = $normalizedRoute; | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| $rootSpan->meta['slim.route.controller'] = $callableName; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,6 +456,10 @@ static function() { | |
|
|
||
| if ($path !== null) { | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $path; | ||
| $normalizedRoute = \DDTrace\Util\RouteNormalizer::normalizeFromSymfony($path); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With Useful? React with 👍 / 👎. |
||
| if ($normalizedRoute !== null) { | ||
| $rootSpan->meta[Tag::APPSEC_NORMALIZED_ROUTE] = $normalizedRoute; | ||
| } | ||
| } | ||
| }; | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -732,7 +732,12 @@ static function (HookData $hook) use ( | |
| function_exists('is_404') && is_404() === false) { | ||
| $rootSpan = \DDTrace\root_span(); | ||
| if (\property_exists($This, 'matched_rule')) { | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $This->matched_rule; | ||
| $matchedRule = $This->matched_rule; | ||
| $rootSpan->meta[Tag::HTTP_ROUTE] = $matchedRule; | ||
| $normalizedRoute = \DDTrace\Util\RouteNormalizer::normalizeFromWordPress($matchedRule); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a WordPress rule contains an optional path capture, only the regex template is passed to the normalizer, so it cannot tell whether that capture participated in the match. For example, the ordinary rule Useful? React with 👍 / 👎. |
||
| if ($normalizedRoute !== null) { | ||
| $rootSpan->meta[Tag::APPSEC_NORMALIZED_ROUTE] = $normalizedRoute; | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
|
||
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.
When no configured route matches,
$uriis the concrete request path rather than a route template. Normalizing it as static text means arbitrary requests such as/users/12345or 404 paths are emitted verbatim in_dd.appsec.normalized_route, retaining parameter values and creating attacker-controlled high-cardinality route tags; this fallback should derive a framework route shape or omit the normalized tag.Useful? React with 👍 / 👎.