summaryrefslogtreecommitdiff
path: root/modules/gallery/libraries
diff options
context:
space:
mode:
authorAndy Staudacher <andy.st@gmail.com>2010-02-27 02:37:39 -0800
committerAndy Staudacher <andy.st@gmail.com>2010-02-27 02:37:39 -0800
commitd9707ae749df2770370dc4eeeeaddda28f092d4d (patch)
tree865a59325fe1fb41d0f89ecf53e3c893254892c4 /modules/gallery/libraries
parent7d2885fe94d8b343af3f8ce1619be13a03056c5e (diff)
Fix for ticket #1036 - Don't echo any sensitive information such as passwords, hashes or personally identifiable information.
Diffstat (limited to 'modules/gallery/libraries')
-rw-r--r--modules/gallery/libraries/MY_Kohana_Exception.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php
index d6f1f467..1712d895 100644
--- a/modules/gallery/libraries/MY_Kohana_Exception.php
+++ b/modules/gallery/libraries/MY_Kohana_Exception.php
@@ -92,4 +92,61 @@ class Kohana_Exception extends Kohana_Exception_Core {
}
print $view;
}
+
+ /**
+ * @see Kohana_Exception::dump()
+ */
+ public static function dump($value, $length=128, $max_level=5) {
+ return self::safe_dump($value, null, $length, $max_level);
+ }
+
+ /**
+ * A safer version of dump(), eliding sensitive information in the dumped
+ * data, such as session ids and passwords / hashes.
+ */
+ public static function safe_dump($value, $key, $length=128, $max_level=5) {
+ return parent::dump(self::_sanitize_for_dump($value, $key), $length, $max_level);
+ }
+
+ /**
+ * Elides sensitive data which shouldn't be echoed to the client,
+ * such as passwords, and other secrets.
+ */
+ /* Visible for testing*/ static function _sanitize_for_dump($value, $key=null) {
+ // Better elide too much than letting something through.
+ // Note: unanchored match is intended.
+ $sensitive_info_pattern =
+ '/(password|pass|email|hash|private_key|session_id|session|g3sid|csrf|secret)/i';
+ if (preg_match($sensitive_info_pattern, $key) ||
+ (is_string($value) && preg_match('/[a-f0-9]{20,}/i', $value))) {
+ return 'removed for display';
+ } else if (is_object($value)) {
+ if ($value instanceof Database) {
+ // Elide database password, host, name, user, etc.
+ return get_class($value) . ' object - details omitted for display';
+ } else if ($value instanceof User_Model) {
+ return get_class($value) . ' object for "' . $value->name . '" - details omitted for display';
+ }
+ return self::_sanitize_for_dump((array) $value, $key);
+ } else if (is_array($value)) {
+ $result = array();
+ foreach ($value as $k => $v) {
+ $actual_key = $k;
+ $key_for_display = $k;
+ if ($k[0] === "\x00") {
+ // Remove the access level from the variable name
+ $actual_key = substr($k, strrpos($k, "\x00") + 1);
+ $access = $k[1] === '*' ? 'protected' : 'private';
+ $key_for_display = "$access: $actual_key";
+ }
+ if (is_object($v)) {
+ $key_for_display .= ' (type: ' . get_class($v) . ')';
+ }
+ $result[$key_for_display] = self::_sanitize_for_dump($v, $actual_key);
+ }
+ } else {
+ $result = $value;
+ }
+ return $result;
+ }
} \ No newline at end of file