diff options
-rw-r--r-- | system/libraries/Security.php | 10 | ||||
-rw-r--r-- | user_guide/libraries/security.html | 5 |
2 files changed, 12 insertions, 3 deletions
diff --git a/system/libraries/Security.php b/system/libraries/Security.php index 9a1590b5c..3c1e9cfba 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -680,11 +680,10 @@ class CI_Security { * @param string * @return string */ - function sanitize_filename($str) + function sanitize_filename($str, $relative_path = FALSE) { $bad = array( "../", - "./", "<!--", "-->", "<", @@ -701,7 +700,6 @@ class CI_Security { '=', ';', '?', - '/', "%20", "%22", "%3c", // < @@ -717,6 +715,12 @@ class CI_Security { "%3b", // ; "%3d" // = ); + + if ( ! $relative_path) + { + $bad[] = './'; + $bad[] = '/'; + } return stripslashes(str_replace($bad, '', $str)); } diff --git a/user_guide/libraries/security.html b/user_guide/libraries/security.html index a50d94846..6d6216d95 100644 --- a/user_guide/libraries/security.html +++ b/user_guide/libraries/security.html @@ -102,6 +102,11 @@ Note: This function should only be used to deal with data upon submission. It's <code>$filename = $this->security->sanitize_filename($this->input->post('filename'));</code> +<p>If it is acceptable for the user input to include relative paths, e.g. <kbd>file/in/some/approved/folder.txt</kbd>, you can set the second optional parameter, + <samp>$relative_path</samp> to TRUE.</p> + +<code>$filename = $this->security->sanitize_filename($this->input->post('filename'), TRUE);</code> + <!-- @todo write docs for CSRF methods --> </div> |