#!/usr/bin/php $line) { if ($buf === '') $start = $n + 1; $buf .= ' '.trim($line); if (preg_match('/[;{}]\s*$/', rtrim($line))) { $out[] = array($start, trim($buf)); $buf = ''; } } if (trim($buf) !== '') $out[] = array($start, trim($buf)); return $out; } function report($file, $line, $text, $why) { return sprintf(" %s:%d %s\n %s", $file, $line, strlen($text) > 100 ? substr($text, 0, 100).' ...' : $text, $why); } $status = 0; $checked = 0; foreach ($renderers as $file) { if (!is_readable($file)) { echo "MISSING: $file\n"; $status = 1; continue; } $findings = array(); foreach (statements($file) as $stmt) { list($line, $text) = $stmt; if (!preg_match('/_COOKIE|_REQUEST/', $text)) continue; if (!preg_match($GLOBALS['is_filter_cookie'], $text)) continue; $checked++; $findings[] = report($file, $line, $text, 'Filter must not look this up; hand the resolved value to addTerm() instead.'); } if ($findings) { echo "RESOLVES IN THE RENDERING LAYER - $file:\n".implode("\n", $findings)."\n\n"; $status = 1; } } foreach ($callers as $file) { if (!is_readable($file)) { echo "MISSING: $file\n"; $status = 1; continue; } $findings = array(); foreach (statements($file) as $stmt) { list($line, $text) = $stmt; if (strpos($text, '_COOKIE') === false) continue; if (!preg_match($is_filter_cookie, $text)) continue; $checked++; if (!preg_match($has_guard, $text)) { $findings[] = report($file, $line, $text, 'Gate this on $use_stored, so a filter given in the request wins.'); } } if ($findings) { echo "UNGUARDED STORED SELECTION - $file:\n".implode("\n", $findings)."\n\n"; $status = 1; } } if ($status === 0) { echo "ok: Filter resolves nothing, and all $checked stored-selection reads are gated\n"; } exit($status);