Skip to content

Commit ae18b39

Browse files
committed
Act on request exec response
1 parent 401d83e commit ae18b39

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

appsec/src/extension/ddappsec.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,14 @@ static PHP_FUNCTION(datadog_appsec_push_params)
498498
return;
499499
}
500500

501-
dd_request_exec(conn, &parameters_zv);
502-
501+
dd_result result = dd_request_exec(conn, &parameters_zv);
503502
zval_ptr_dtor(&parameters_zv);
503+
504+
if (result == dd_should_block) {
505+
dd_request_abort_static_page();
506+
} else if (result == dd_should_redirect) {
507+
dd_request_abort_redirect();
508+
}
504509
}
505510

506511
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Push params gets blocked
3+
--INI--
4+
extension=ddtrace.so
5+
datadog.appsec.enabled=1
6+
--FILE--
7+
<?php
8+
use function datadog\appsec\testing\{rinit,rshutdown};
9+
use function datadog\appsec\push_params;
10+
11+
include __DIR__ . '/inc/mock_helper.php';
12+
13+
$helper = Helper::createInitedRun([
14+
response_list(response_request_init(['ok', []])),
15+
response_list(response_request_exec(['block', ['status_code' => '404', 'type' => 'json'], ['{"found":"attack"}','{"another":"attack"}']])),
16+
]);
17+
18+
rinit();
19+
push_params(["some" => "params", "more" => "parameters"]);
20+
21+
var_dump("THIS SHOULD NOT GET IN THE OUTPUT");
22+
23+
?>
24+
--EXPECTHEADERS--
25+
Status: 404 Not Found
26+
Content-type: application/json
27+
--EXPECTF--
28+
{"errors": [{"title": "You've been blocked", "detail": "Sorry, you cannot access this page. Please contact the customer service team. Security provided by Datadog."}]}
29+
Warning: datadog\appsec\push_params(): Datadog blocked the request and presented a static error page in %s on line %d

appsec/tests/extension/push_params.phpt renamed to appsec/tests/extension/push_params_ok.phpt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
--TEST--
2-
Push params ara sent on request_exec
2+
Push params are sent on request_exec
33
--INI--
44
extension=ddtrace.so
5-
datadog.appsec.waf_timeout=42
65
datadog.appsec.enabled=1
7-
--ENV--
8-
DD_TRACE_GENERATE_ROOT_SPAN=0
9-
REQUEST_URI=/static01/dynamic01/static02/dynamic02
10-
URL_SCHEME=http
11-
HTTP_CONTENT_TYPE=text/plain
12-
HTTP_CONTENT_LENGTH=0
136
--FILE--
147
<?php
158
use function datadog\appsec\testing\{rinit,rshutdown};
@@ -49,4 +42,4 @@ array(2) {
4942
}
5043
}
5144
}
52-
}
45+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Push params gets blocked
3+
--INI--
4+
extension=ddtrace.so
5+
datadog.appsec.enabled=1
6+
--FILE--
7+
<?php
8+
use function datadog\appsec\testing\{rinit,rshutdown};
9+
use function datadog\appsec\push_params;
10+
11+
include __DIR__ . '/inc/mock_helper.php';
12+
13+
$helper = Helper::createInitedRun([
14+
response_list(response_request_init(['ok', []])),
15+
response_list(response_request_exec(['redirect', ['status_code' => '303', 'location' => 'https://datadoghq.com'], []])),
16+
]);
17+
18+
rinit();
19+
push_params(["some" => "params", "more" => "parameters"]);
20+
21+
var_dump("THIS SHOULD NOT GET IN THE OUTPUT");
22+
23+
?>
24+
--EXPECTHEADERS--
25+
Status: 303 See Other
26+
Content-type: text/html; charset=UTF-8
27+
--EXPECTF--
28+
Warning: datadog\appsec\push_params(): Datadog blocked the request and attempted a redirection to https://datadoghq.com in %s on line %d

0 commit comments

Comments
 (0)