File tree Expand file tree Collapse file tree 7 files changed +24
-0
lines changed Expand file tree Collapse file tree 7 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 145
145
?>
146
146
<h2><?php echo $ edit ? 'Edit ' : 'Add ' ?> </h2>
147
147
<form action="<?php echo format_html (getRelativePath ('edit.php ' ))?> " method="post">
148
+ <input type="hidden" name="csrf" value="<?php echo $ csrfToken ; ?> " />
148
149
149
150
<p>
150
151
<label for="type">Type:</label>
Original file line number Diff line number Diff line change @@ -187,6 +187,7 @@ function export_json($key) {
187
187
<h2>Export <?php echo isset ($ _GET ['key ' ]) ? format_html ($ _GET ['key ' ]) : '' ?> </h2>
188
188
189
189
<form action="<?php echo format_html (getRelativePath ('export.php ' ))?> " method="post">
190
+ <input type="hidden" name="csrf" value="<?php echo $ csrfToken ; ?> " />
190
191
191
192
<p>
192
193
<label for="type">Type:</label>
Original file line number Diff line number Diff line change 92
92
?>
93
93
<h2>Import</h2>
94
94
<form action="<?php echo format_html (getRelativePath ('import.php ' ))?> " method="post">
95
+ <input type="hidden" name="csrf" value="<?php echo $ csrfToken ; ?> " />
95
96
96
97
<p>
97
98
<label for="commands">Commands:<br>
Original file line number Diff line number Diff line change 4
4
define ('PHPREDIS_ADMIN_PATH ' , dirname (__DIR__ ));
5
5
6
6
7
+ if (session_status () !== PHP_SESSION_DISABLED ) {
8
+ session_start ();
9
+
10
+ if (isset ($ _SESSION ['phpredisadmin_csrf ' ])) {
11
+ $ csrfToken = $ _SESSION ['phpredisadmin_csrf ' ];
12
+ } else {
13
+ $ csrfToken = bin2hex (random_bytes (16 ));
14
+ $ _SESSION ['phpredisadmin_csrf ' ] = $ csrfToken ;
15
+ }
16
+ } else {
17
+ $ csrfToken = 'nosession ' ;
18
+ }
19
+
20
+ if ($ _SERVER ['REQUEST_METHOD ' ] === 'POST ' ) {
21
+ if ($ _POST ['csrf ' ] !== $ csrfToken ) {
22
+ die ('bad csrf token ' );
23
+ }
24
+ }
7
25
8
26
9
27
// These includes are needed by each script.
Original file line number Diff line number Diff line change 13
13
<h1 class="logo">phpRedisAdmin</h1>
14
14
15
15
<form class="form-signin" method="post" action="login.php">
16
+ <input type="hidden" name="csrf" value="<?php echo $ csrfToken ; ?> " />
16
17
<h2 class="form-signin-heading">Please log in</h2>
17
18
18
19
<?php if (isset ($ _POST ['username ' ]) || isset ($ _POST ['password ' ])): ?>
Original file line number Diff line number Diff line change 36
36
?>
37
37
<h2>Edit Name of <?php echo format_html ($ _GET ['key ' ])?> </h2>
38
38
<form action="<?php echo format_html (getRelativePath ('rename.php ' ))?> " method="post">
39
+ <input type="hidden" name="csrf" value="<?php echo $ csrfToken ; ?> " />
39
40
40
41
<input type="hidden" name="old" value="<?php echo format_html ($ _GET ['key ' ])?> ">
41
42
Original file line number Diff line number Diff line change 27
27
?>
28
28
<h2>Edit TTL</h2>
29
29
<form action="<?php echo format_html (getRelativePath ('ttl.php ' ))?> " method="post">
30
+ <input type="hidden" name="csrf" value="<?php echo $ csrfToken ; ?> " />
30
31
31
32
<p>
32
33
<label for="key">Key:</label>
You can’t perform that action at this time.
0 commit comments