-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFuzzParams.php
More file actions
69 lines (61 loc) · 1.97 KB
/
Copy pathFuzzParams.php
File metadata and controls
69 lines (61 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace FediE2EE\PKDServer\Fuzzing;
use FediE2EE\PKDServer\Exceptions\DependencyException;
use FediE2EE\PKDServer\Meta\Params;
use PhpFuzzer\Config;
use TypeError;
/** @var Config $config */
require_once dirname(__DIR__) . '/vendor/autoload.php';
$config->setTarget(function (string $input): void {
$decoded = json_decode($input, true);
// Test hash algorithm validation
$hashAlgos = [
'sha256', // Valid
'sha384', // Valid
'sha512', // Valid
'blake2b', // Valid
'md5', // Invalid (insecure)
'sha1', // Invalid (insecure)
'crc32', // Invalid (not a hash)
$input, // Fuzzed value
];
foreach ($hashAlgos as $algo) {
try {
$params = new Params(hashAlgo: $algo);
// If we got here, the algo was accepted
assert(in_array($algo, ['sha256', 'sha384', 'sha512', 'blake2b'], true));
} catch (DependencyException) {
// Expected for invalid algorithms
} catch (TypeError) {
// Expected for non-string input
}
}
// Test hostname validation with fuzzed values
$hostnames = [
'localhost',
'example.com',
'sub.example.com',
'192.168.1.1',
'',
'invalid hostname',
'-invalid.com',
'invalid-.com',
str_repeat('a', 64) . '.com',
];
// Also try the raw input as hostname
if (strlen($input) > 0 && strlen($input) <= 253) {
$hostnames[] = $input;
}
foreach ($hostnames as $hostname) {
try {
$params = new Params(hostname: $hostname);
// If we got here, the hostname was accepted
assert(filter_var($hostname, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) !== false);
} catch (DependencyException) {
// Expected for invalid hostnames
} catch (TypeError) {
// Expected for non-string input
}
}
});