aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/graph.php
diff options
context:
space:
mode:
authorPeter Wu2014-07-21 11:09:21 +0200
committerPeter Wu2014-07-21 11:09:21 +0200
commited418551cdb76a72c1323fd32cb3ef6f58e697d5 (patch)
treedba230c2b1b007dbc3fd768badad0e0a999d4b7e /graph.php
parentFix overly permissive hostname validation, fix host check (diff)
downloadapt-panopticon_cgp-ed418551cdb76a72c1323fd32cb3ef6f58e697d5.zip
apt-panopticon_cgp-ed418551cdb76a72c1323fd32cb3ef6f58e697d5.tar.gz
apt-panopticon_cgp-ed418551cdb76a72c1323fd32cb3ef6f58e697d5.tar.bz2
apt-panopticon_cgp-ed418551cdb76a72c1323fd32cb3ef6f58e697d5.tar.xz
Better x and y validation, report 400 on errors
Report 400 Bad Request on query errors instead of reporting 200 OK (which can be cached). Add some additional validation for the 'x' and 'y' parameters, to catch underflow (test with `x=-10` for example). Also fix a typo in the error message and include more details (the actual error).
Diffstat (limited to 'graph.php')
-rw-r--r--graph.php22
1 files changed, 15 insertions, 7 deletions
diff --git a/graph.php b/graph.php
index 3e33b92..2d62d92 100644
--- a/graph.php
+++ b/graph.php
@@ -6,16 +6,24 @@ require_once 'inc/collectd.inc.php';
6 6
7$plugin = validate_get(GET('p'), 'plugin'); 7$plugin = validate_get(GET('p'), 'plugin');
8$type = validate_get(GET('t'), 'type'); 8$type = validate_get(GET('t'), 'type');
9$width = empty($_GET['x']) ? $CONFIG['width'] : $_GET['x']; 9$width = GET('x') ? filter_input(INPUT_GET, 'x', FILTER_VALIDATE_INT, array(
10$height = empty($_GET['y']) ? $CONFIG['height'] : $_GET['y']; 10 'min_range' => 10,
11 11 'max_range' => $CONFIG['max-width']
12if (validate_get(GET('h'), 'host') === NULL) { 12)) : $CONFIG['width'];
13 error_log('CGP Error: plugin contains unknown characters'); 13$height = GET('y') ? filter_input(INPUT_GET, 'y', FILTER_VALIDATE_INT, array(
14 'min_range' => 10,
15 'max_range' => $CONFIG['max-height']
16)) : $CONFIG['height'];
17
18if ($width === NULL || $height === NULL) {
19 error_log(sprintf('Invalid image dimension, x="%s", y="%s"',
20 urlencode(GET('x')),
21 urlencode(GET('y'))));
14 error_image(); 22 error_image();
15} 23}
16 24
17if ($width > $CONFIG['max-width'] || $height > $CONFIG['max-height']) { 25if (validate_get(GET('h'), 'host') === NULL) {
18 error_log('Resquested image is too large. Please configure max-width and max-height.'); 26 error_log('Invalid host: "' . urlencode(GET('h')) . '"');
19 error_image(); 27 error_image();
20} 28}
21 29