<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -54,6 +54,12 @@
       #(.startsWith (.toLowerCase (.getName %)) &quot;index.&quot;)
        (.listFiles dir))))
 
+(defn safe-path?
+  &quot;Is a filepath safe for a particular root?&quot;
+  [root path]
+  (.startsWith (.getCanonicalPath (File. root path))
+               (.getCanonicalPath (File. root))))
+
 (defn serve-file
   &quot;Attempts to serve up a static file from a directory, which defaults to
   './public'. Nil is returned if the file does not exist. If the file is a
@@ -62,8 +68,9 @@
     (serve-file &quot;public&quot; path))
   ([root path]
     (let [filepath (File. root path)]
-      (cond
-        (.isFile filepath)
-          filepath
-        (.isDirectory filepath)
-          (find-index-file filepath)))))
+      (if (safe-path? root path)
+        (cond 
+          (.isFile filepath)
+            filepath
+          (.isDirectory filepath)
+            (find-index-file filepath))))))</diff>
      <filename>src/compojure/http/helpers.clj</filename>
    </modified>
    <modified>
      <diff>@@ -15,3 +15,7 @@
 (deftest test-content-type
   (is (= (content-type &quot;text/html&quot;)
          {:headers {&quot;Content-Type&quot; &quot;text/html&quot;}})))
+
+(deftest test-safe-path
+  (is (not (safe-path? &quot;/home/compojure&quot; &quot;../private/secret.txt&quot;)))
+  (is (safe-path? &quot;/home/compojure&quot; &quot;public/index.html&quot;)))</diff>
      <filename>test/compojure/http/helpers.clj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fda98248260d7d6285c0262da9ac6bfd48620254</id>
    </parent>
  </parents>
  <author>
    <name>weavejester</name>
    <email>jreeves@weavejester.com</email>
  </author>
  <url>http://github.com/abedra/compojure/commit/81fae95902f645ef3912fabb38dfcef9d29b6224</url>
  <id>81fae95902f645ef3912fabb38dfcef9d29b6224</id>
  <committed-date>2009-09-13T07:38:17-07:00</committed-date>
  <authored-date>2009-09-13T07:38:01-07:00</authored-date>
  <message>Added protection against malformed file paths as reported by Meredydd
Luff</message>
  <tree>0706b984ff8e54a1ae4b4bc0abce8b2e0f1b22c9</tree>
  <committer>
    <name>weavejester</name>
    <email>jreeves@weavejester.com</email>
  </committer>
</commit>
