Skip to content

Commit 1c994bd

Browse files
limit keys to 30 characters
1 parent bce70f8 commit 1c994bd

File tree

6 files changed

+44
-24
lines changed

6 files changed

+44
-24
lines changed

common.inc.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515

1616

1717
$redis = new Redis();
18-
if (!$redis->connect($config['host'], $config['port'])) {
18+
19+
try {
20+
$redis->connect($config['host'], $config['port']);
21+
} catch (Exception $e) {
1922
die('ERROR: Could not connect to Redis');
2023
}
2124

25+
2226
if (isset($config['auth'])) {
2327
if (!$redis->auth($config['auth'])) {
2428
die('ERROR: Authentication failed.');

delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
require 'header.inc.php';
2525
?>
2626
<script>
27-
top.location.href = top.location.pathname+'?view&key=<?=format_html($_GET['key'])?>';
27+
top.location.href = top.location.pathname+'?view&key=<?=urlencode($_GET['key'])?>';
2828
</script>
2929
<?
3030
require 'footer.inc.php';

edit.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55

66

77

8-
if (isset($_POST['type'], $_POST['key'], $_POST['value'])) {
8+
while (isset($_POST['type'], $_POST['key'], $_POST['value'])) {
9+
if (strlen($_POST['key']) > 30) {
10+
break;
11+
}
12+
913
if ($_POST['type'] == 'string') {
1014
$redis->set($_POST['key'], $_POST['value']);
1115
} else if (($_POST['type'] == 'hash') && isset($_POST['hkey'])) {
16+
if (strlen($_POST['hkey']) > 30) {
17+
break;
18+
}
19+
1220
$redis->hSet($_POST['key'], $_POST['hkey'], $_POST['value']);
1321
} else if (($_POST['type'] == 'list') && isset($_POST['index'])) {
1422
$size = $redis->lSize($_POST['key']);
@@ -29,7 +37,7 @@
2937
require 'header.inc.php';
3038
?>
3139
<script>
32-
top.location.href = top.location.pathname+'?view&key=<?=format_html($_POST['key'])?>';
40+
top.location.href = top.location.pathname+'?view&key=<?=urlencode($_POST['key'])?>';
3341
</script>
3442
<?
3543
require 'footer.inc.php';
@@ -74,12 +82,12 @@
7482

7583
<p>
7684
<label for="key">Key:</label>
77-
<input type="text" name="key" id="key" size="30" <?=isset($_GET['key']) ? 'value="'.format_html($_GET['key']).'"' : ''?>>
85+
<input type="text" name="key" id="key" size="30" maxlength="30" <?=isset($_GET['key']) ? 'value="'.format_html($_GET['key']).'"' : ''?>>
7886
</p>
7987

8088
<p id="hkeyp">
8189
<label for="khey">Hash key:</label>
82-
<input type="text" name="hkey" id="hkey" size="30" <?=isset($_GET['hkey']) ? 'value="'.format_html($_GET['hkey']).'"' : ''?>>
90+
<input type="text" name="hkey" id="hkey" size="30" maxlength="30" <?=isset($_GET['hkey']) ? 'value="'.format_html($_GET['hkey']).'"' : ''?>>
8391
</p>
8492

8593
<p id="indexp">

index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
$dirs = array();
3737

3838
foreach ($keys as $key) {
39+
if (strlen($key) > 30) {
40+
continue;
41+
}
42+
3943
$key = explode($config['seperator'], $key);
4044

4145
$a = &$dirs;
@@ -76,7 +80,7 @@ function print_tree($item, $key, $all, $last) {
7680

7781
?>
7882
<li<?=empty($class) ? '' : ' class="'.implode(' ', $class).'"'?>>
79-
<a href="http://github.com/?view&amp;key=%3Cspan%20class="pl-ent"><?=format_html($all)?>"><?=format_html($key)?><?
83+
<a href="http://github.com/?view&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($all)?>"><?=format_html($key)?><?
8084

8185
$len = false;
8286

rename.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66

77

8-
if (isset($_POST['old'], $_POST['key'])) {
8+
while (isset($_POST['old'], $_POST['key'])) {
9+
if (strlen($_POST['key']) > 30) {
10+
break;
11+
}
12+
913
$redis->rename($_POST['old'], $_POST['key']);
1014

1115
require 'header.inc.php';
1216
?>
1317
<script>
14-
top.location.href = top.location.pathname+'?view&key=<?=format_html($_POST['key'])?>';
18+
top.location.href = top.location.pathname+'?view&key=<?=urlencode($_POST['key'])?>';
1519
</script>
1620
<?
1721
require 'footer.inc.php';

view.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
<?
2626
if ($exists) {
2727
?>
28-
<a href="http://github.com/rename.php?key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a>
29-
<a href="http://github.com/delete.php?key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>" class="delkey"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
30-
<a href="http://github.com/export.php?key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>"><img src="http://github.com/images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
28+
<a href="http://github.com/rename.php?key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Rename" alt="[R]"></a>
29+
<a href="http://github.com/delete.php?key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>" class="delkey"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
30+
<a href="http://github.com/export.php?key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>"><img src="http://github.com/images/export.png" width="16" height="16" title="Export" alt="[E]"></a>
3131
<?
3232
}
3333
?>
@@ -67,7 +67,7 @@
6767

6868
<tr><td><div>Type:</div></td><td><div><?=format_html($type)?></div></td></tr>
6969

70-
<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?=($ttl == -1) ? 'does not expire' : $ttl?> <a href="http://github.com/ttl.php?key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;ttl=<?=$ttl?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr>
70+
<tr><td><div><abbr title="Time To Live">TTL</abbr>:</div></td><td><div><?=($ttl == -1) ? 'does not expire' : $ttl?> <a href="http://github.com/ttl.php?key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;ttl=<?=$ttl?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit TTL" alt="[E]" class="imgbut"></a></div></td></tr>
7171

7272
<tr><td><div>Encoding:</div></td><td><div><?=format_html($encoding)?></div></td></tr>
7373

@@ -82,9 +82,9 @@
8282
?>
8383
<table>
8484
<tr><td><div><?=nl2br(format_html($value))?></div></td><td><div>
85-
<a href="http://github.com/edit.php?type=string&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
85+
<a href="http://github.com/edit.php?type=string&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
8686
</div></td><td><div>
87-
<a href="http://github.com/delete.php?type=string&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
87+
<a href="http://github.com/delete.php?type=string&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
8888
</div></td></tr>
8989
</table>
9090
<?
@@ -97,9 +97,9 @@
9797
foreach ($values as $hkey => $value) {
9898
?>
9999
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=format_html($hkey)?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div>
100-
<a href="http://github.com/edit.php?type=hash&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;hkey=<?=format_html($hkey)?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
100+
<a href="http://github.com/edit.php?type=hash&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;hkey=<?=urlencode($hkey)?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
101101
</div></td><td><div>
102-
<a href="http://github.com/delete.php?type=hash&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;hkey=<?=format_html($hkey)?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
102+
<a href="http://github.com/delete.php?type=hash&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;hkey=<?=urlencode($hkey)?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
103103
</div></td></tr>
104104
<?
105105

@@ -116,9 +116,9 @@
116116

117117
?>
118118
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$i?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div>
119-
<a href="http://github.com/edit.php?type=list&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;index=<?=$i?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
119+
<a href="http://github.com/edit.php?type=list&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;index=<?=$i?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
120120
</div></td><td><div>
121-
<a href="http://github.com/delete.php?type=list&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;index=<?=$i?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
121+
<a href="http://github.com/delete.php?type=list&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;index=<?=$i?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
122122
</div></td></tr>
123123
<?
124124

@@ -133,9 +133,9 @@
133133
foreach ($values as $value) {
134134
?>
135135
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=nl2br(format_html($value))?></div></td><td><div>
136-
<a href="http://github.com/edit.php?type=set&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;value=<?=urlencode($value)?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
136+
<a href="http://github.com/edit.php?type=set&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;value=<?=urlencode($value)?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
137137
</div></td><td><div>
138-
<a href="http://github.com/delete.php?type=set&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
138+
<a href="http://github.com/delete.php?type=set&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
139139
</div></td></tr>
140140
<?
141141

@@ -152,8 +152,8 @@
152152

153153
?>
154154
<tr <?=$alt ? 'class="alt"' : ''?>><td><div><?=$score?></div></td><td><div><?=nl2br(format_html($value))?></div></td><td><div>
155-
<a href="http://github.com/edit.php?type=zset&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;score=<?=$score?>&amp;value=<?=urlencode($value)?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
156-
<a href="http://github.com/delete.php?type=zset&amp;key=%3Cspan%20class="pl-ent"><?=format_html($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
155+
<a href="http://github.com/edit.php?type=zset&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;score=<?=$score?>&amp;value=<?=urlencode($value)?>"><img src="http://github.com/images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
156+
<a href="http://github.com/delete.php?type=zset&amp;key=%3Cspan%20class="pl-ent"><?=urlencode($_GET['key'])?>&amp;value=<?=urlencode($value)?>" class="delval"><img src="http://github.com/images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
157157
</div></td></tr>
158158
<?
159159

@@ -166,7 +166,7 @@
166166
</table>
167167

168168
<p>
169-
<a href="http://github.com/edit.php?type=%3Cspan%20class="pl-ent"><?=$type?>&amp;key=<?=format_html($_GET['key'])?>" class="add">Add another value</a>
169+
<a href="http://github.com/edit.php?type=%3Cspan%20class="pl-ent"><?=$type?>&amp;key=<?=urlencode($_GET['key'])?>" class="add">Add another value</a>
170170
</p>
171171
<?
172172
}

0 commit comments

Comments
 (0)