Skip to content

Commit f44027c

Browse files
committed
Address comments from PR
1 parent 613de3d commit f44027c

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

appsec/src/extension/ddappsec.c

-4
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,6 @@ static PHP_FUNCTION(datadog_appsec_push_addresses)
498498
return;
499499
}
500500

501-
if (addresses == NULL) {
502-
return;
503-
}
504-
505501
zend_array *parameters_arr =
506502
zend_new_array(zend_hash_num_elements(addresses));
507503
zval parameters_zv;

src/DDTrace/Integrations/Filesystem/FilesystemIntegration.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ private static function preHook($variant)
6565
$addresses["server.io.fs.file"] = $hook->args[0];
6666
}
6767

68-
if (in_array($variant, ['file_get_contents', 'fopen']) && (empty($protocol) || $protocol === 'http')) {
68+
if (in_array($variant, ['file_get_contents', 'fopen']) &&
69+
(empty($protocol) || in_array($protocol, ['http', 'https', 'ftp', 'ftps']))) {
6970
$addresses["server.io.net.url"] = $hook->args[0];
7071

7172
}

tests/Integrations/Filesystem/FilesystemTest.php

+31-5
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,47 @@ public function testFileProtocol()
5656
$this->assertEvent('file://'. $file, $traces);
5757
}
5858

59-
public function testHttpProtocol()
59+
public function raspProtocols()
6060
{
61-
$file = 'http://example.com';
62-
$traces = $this->tracesFromWebRequest(function () use ($file) {
63-
$response = $this->call(GetSpec::create('Root', '/?function=fopen&path='.$file));
61+
return [
62+
['http'],
63+
['https'],
64+
['ftp'],
65+
['ftps']
66+
];
67+
}
68+
69+
/**
70+
* @dataProvider raspProtocols
71+
*/
72+
public function testRaspProtocols($protocol)
73+
{
74+
$url = $protocol.'://example.com';
75+
$traces = $this->tracesFromWebRequest(function () use ($url) {
76+
$response = $this->call(GetSpec::create('Root', '/?function=fopen&path='.$url));
6477
TestCase::assertSame('OK', $response);
6578
});
6679

6780
$events = AppsecStatus::getInstance()->getEvents();
6881
$this->assertEquals(1, count($events));
69-
$this->assertEquals($file, $events[0][0]["server.io.net.url"]);
82+
$this->assertEquals(1, count($events[0][0]));
83+
$this->assertEquals($url, $events[0][0]["server.io.net.url"]);
7084
$this->assertEquals('push_addresses', $events[0]['eventName']);
7185
$this->assertTrue($events[0]['rasp']);
7286
}
7387

88+
public function testInvalidProtocol()
89+
{
90+
$url = 'bad://example.com';
91+
$traces = $this->tracesFromWebRequest(function () use ($url) {
92+
$response = $this->call(GetSpec::create('Root', '/?function=fopen&path='.$url));
93+
TestCase::assertSame('OK', $response);
94+
});
95+
96+
$events = AppsecStatus::getInstance()->getEvents();
97+
$this->assertEquals(0, count($events));
98+
}
99+
74100
public function testFilePutContents()
75101
{
76102
$traces = $this->tracesFromWebRequest(function () {

tests/Integrations/Filesystem/index.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
switch ($function) {
99
case 'file_put_contents':
10-
file_put_contents($path, 'some content');
10+
@file_put_contents($path, 'some content');
1111
break;
1212
case 'fopen':
13-
fopen($path, 'r');
13+
@fopen($path, 'r');
1414
break;
1515
default:
16-
$function($path);
16+
@$function($path);
1717
break;
1818
}
1919

0 commit comments

Comments
 (0)