-
Notifications
You must be signed in to change notification settings - Fork 179
feat(appsec): collect security-testing headers on HTTP entry spans #3925
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
Open
christophe-papazian
wants to merge
7
commits into
master
Choose a base branch
from
christophe-papazian/security-testing-headers
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.
+187
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6881f35
feat(appsec): collect security-testing headers on HTTP entry spans (A…
christophe-papazian 213245c
Address review: move header collection to tags.c, drop CHANGELOG
christophe-papazian 798aef9
Address review comments on security-testing headers
christophe-papazian 4c5519d
Remove redundant AppSec tags.c collection
christophe-papazian 77e7c81
Revert ancillary_tags.phpt to master state
christophe-papazian 7f3ca82
Fix stale comment in serializer.c
christophe-papazian 90d1460
Inject security-testing headers into DD_TRACE_HEADER_TAGS at startup
christophe-papazian 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 hidden or 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 hidden or 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,71 @@ | ||
| <?php | ||
|
|
||
| namespace DDTrace\Tests\Integrations\Swoole; | ||
|
|
||
| use DDTrace\Tests\Common\WebFrameworkTestCase; | ||
| use DDTrace\Tests\Frameworks\Util\Request\GetSpec; | ||
|
|
||
| class SecurityTestingHeadersTest extends WebFrameworkTestCase | ||
| { | ||
| public static function getAppIndexScript() | ||
| { | ||
| return __DIR__ . '/../../Frameworks/Swoole/index.php'; | ||
| } | ||
|
|
||
| protected static function isSwoole() | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| protected static function getEnvs() | ||
| { | ||
| return array_merge(parent::getEnvs(), [ | ||
| 'DD_TRACE_CLI_ENABLED' => 'true', | ||
| ]); | ||
| } | ||
|
|
||
| protected static function getInis() | ||
| { | ||
| return array_merge(parent::getInis(), [ | ||
| 'extension' => 'swoole.so', | ||
| ]); | ||
| } | ||
|
|
||
| public function testSecurityTestingHeadersCollectedUnconditionally() | ||
| { | ||
| $traces = $this->tracesFromWebRequest(function () { | ||
| $spec = GetSpec::create('request', '/', [ | ||
| 'X-Datadog-Endpoint-Scan: endpoint-scan-uuid', | ||
| 'X-Datadog-Security-Test: security-test-uuid', | ||
| ]); | ||
| $this->call($spec); | ||
| }); | ||
|
|
||
| $span = $traces[0][0]; | ||
| $this->assertSame( | ||
| 'endpoint-scan-uuid', | ||
| $span['meta']['http.request.headers.x-datadog-endpoint-scan'] | ||
| ); | ||
| $this->assertSame( | ||
| 'security-test-uuid', | ||
| $span['meta']['http.request.headers.x-datadog-security-test'] | ||
| ); | ||
| } | ||
|
|
||
| public function testSecurityTestingHeadersAbsentWhenNotSent() | ||
| { | ||
| $traces = $this->tracesFromWebRequest(function () { | ||
| $this->call(GetSpec::create('request', '/')); | ||
| }); | ||
|
|
||
| $span = $traces[0][0]; | ||
| $this->assertArrayNotHasKey( | ||
| 'http.request.headers.x-datadog-endpoint-scan', | ||
| $span['meta'] | ||
| ); | ||
| $this->assertArrayNotHasKey( | ||
| 'http.request.headers.x-datadog-security-test', | ||
| $span['meta'] | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,50 @@ | ||
| --TEST-- | ||
| Security-testing headers are forwarded to the inferred proxy span | ||
| --ENV-- | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| DD_CODE_ORIGIN_FOR_SPANS_ENABLED=0 | ||
| DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED=1 | ||
| HTTP_X_DD_PROXY=aws-apigateway | ||
| HTTP_X_DD_PROXY_REQUEST_TIME_MS=100 | ||
| HTTP_X_DD_PROXY_PATH=/test | ||
| HTTP_X_DD_PROXY_HTTPMETHOD=GET | ||
| HTTP_X_DD_PROXY_DOMAIN_NAME=example.com | ||
| HTTP_X_DD_PROXY_STAGE=aws-prod | ||
| HTTP_X_DATADOG_ENDPOINT_SCAN=endpoint-scan-uuid | ||
| HTTP_X_DATADOG_SECURITY_TEST=security-test-uuid | ||
| METHOD=GET | ||
| SERVER_NAME=localhost:8888 | ||
| SCRIPT_NAME=/foo.php | ||
| REQUEST_URI=/foo | ||
| DD_TRACE_DEBUG_PRNG_SEED=42 | ||
| --FILE-- | ||
| <?php | ||
| DDTrace\start_span(); | ||
| DDTrace\close_span(); | ||
| $spans = dd_trace_serialize_closed_spans(); | ||
|
|
||
| // The PHP service-entry span has a parent_id pointing to the inferred span; | ||
| // the inferred span itself has no parent_id (it is the trace root). | ||
| $rootSpan = null; | ||
| $inferredSpan = null; | ||
| foreach ($spans as $span) { | ||
| if (!isset($span['parent_id'])) { | ||
| $inferredSpan = $span; | ||
| } else { | ||
| $rootSpan = $span; | ||
| } | ||
| } | ||
|
|
||
| // Tags must be present on the PHP service-entry span | ||
| var_dump($rootSpan['meta']['http.request.headers.x-datadog-endpoint-scan'] ?? 'NOT SET'); | ||
| var_dump($rootSpan['meta']['http.request.headers.x-datadog-security-test'] ?? 'NOT SET'); | ||
| // And forwarded to the inferred proxy span | ||
| var_dump($inferredSpan['meta']['http.request.headers.x-datadog-endpoint-scan'] ?? 'NOT SET'); | ||
| var_dump($inferredSpan['meta']['http.request.headers.x-datadog-security-test'] ?? 'NOT SET'); | ||
| ?> | ||
| --EXPECT-- | ||
| string(18) "endpoint-scan-uuid" | ||
| string(18) "security-test-uuid" | ||
| string(18) "endpoint-scan-uuid" | ||
| string(18) "security-test-uuid" |
This file contains hidden or 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,19 @@ | ||
| --TEST-- | ||
| Security-testing headers are collected unconditionally on the root span | ||
| --ENV-- | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| DD_TRACE_HEADER_TAGS= | ||
| HTTP_X_DATADOG_ENDPOINT_SCAN=endpoint-scan-uuid | ||
| HTTP_X_DATADOG_SECURITY_TEST=security-test-uuid | ||
| --FILE-- | ||
| <?php | ||
| DDTrace\start_span(); | ||
| DDTrace\close_span(0); | ||
| $spans = dd_trace_serialize_closed_spans(); | ||
| var_dump($spans[0]['meta']['http.request.headers.x-datadog-endpoint-scan']); | ||
| var_dump($spans[0]['meta']['http.request.headers.x-datadog-security-test']); | ||
| ?> | ||
| --EXPECT-- | ||
| string(18) "endpoint-scan-uuid" | ||
| string(18) "security-test-uuid" |
This file contains hidden or 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,16 @@ | ||
| --TEST-- | ||
| Security-testing header tags are absent when headers are not sent | ||
| --ENV-- | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| --FILE-- | ||
| <?php | ||
| DDTrace\start_span(); | ||
| DDTrace\close_span(0); | ||
| $spans = dd_trace_serialize_closed_spans(); | ||
| var_dump(array_key_exists('http.request.headers.x-datadog-endpoint-scan', $spans[0]['meta'])); | ||
| var_dump(array_key_exists('http.request.headers.x-datadog-security-test', $spans[0]['meta'])); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(false) | ||
| bool(false) |
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.