|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HtaccessCapabilityTester\Testers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Say you have a rewrite rule that points to a PHP script and you would like to pass some information |
|
7
|
|
|
* along to the PHP. Usually, you will just pass it in the query string. But this won't do if the information |
|
8
|
|
|
* is sensitive. In that case, there are some tricks available. The trick being tested here sets tells the |
|
9
|
|
|
* RewriteRule directive to set an environment variable which a RequestHeader directive picks up on and passes |
|
10
|
|
|
* on to the script in a request header. |
|
11
|
|
|
* |
|
12
|
|
|
* @package HtaccessCapabilityTester |
|
13
|
|
|
* @author Bjørn Rosell <[email protected]> |
|
14
|
|
|
* @since Class available since 0.7 |
|
15
|
|
|
*/ |
|
16
|
|
|
class PassInfoFromRewriteToScriptThroughRequestHeaderTester extends CustomTester |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
6 |
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
$htaccessFile = <<<'EOD' |
|
27
|
6 |
|
<IfModule mod_rewrite.c> |
|
28
|
|
|
RewriteEngine On |
|
29
|
|
|
# We pass document root, because that can easily be checked by the script |
|
30
|
|
|
RewriteRule ^test\.php$ - [E=PASSTHROUGHHEADER:%{DOCUMENT_ROOT},L] |
|
31
|
|
|
|
|
32
|
|
|
<IfModule mod_headers.c> |
|
33
|
|
|
RequestHeader set PASSTHROUGHHEADER "%{PASSTHROUGHHEADER}e" env=PASSTHROUGHHEADER |
|
34
|
|
|
</IfModule> |
|
35
|
|
|
|
|
36
|
|
|
</IfModule> |
|
37
|
|
|
EOD; |
|
38
|
|
|
|
|
39
|
|
|
$phpFile = <<<'EOD' |
|
40
|
6 |
|
<?php |
|
41
|
|
|
if (isset($_SERVER['HTTP_PASSTHROUGHHEADER'])) { |
|
42
|
|
|
echo ($_SERVER['HTTP_PASSTHROUGHHEADER'] == $_SERVER['DOCUMENT_ROOT'] ? 1 : 0); |
|
43
|
|
|
exit; |
|
44
|
|
|
} |
|
45
|
|
|
echo '0'; |
|
46
|
|
|
EOD; |
|
47
|
|
|
|
|
48
|
|
|
$test = [ |
|
49
|
6 |
|
'subdir' => 'pass-info-from-rewrite-to-script-through-request-header', |
|
50
|
|
|
'files' => [ |
|
51
|
6 |
|
['.htaccess', $htaccessFile], |
|
52
|
6 |
|
['test.php', $phpFile], |
|
53
|
|
|
], |
|
54
|
6 |
|
'request' => 'test.php', |
|
55
|
|
|
'interpretation' => [ |
|
56
|
|
|
['success', 'body', 'equals', '1'], |
|
57
|
|
|
['failure', 'body', 'equals', '0'], |
|
58
|
|
|
['inconclusive', 'body', 'begins-with', '<' . '?php'], |
|
59
|
|
|
['inconclusive'] |
|
60
|
|
|
] |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
6 |
|
parent::__construct($test); |
|
64
|
6 |
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|