Bladeren bron

static files: allow files in a subdirectory

allowing '/' in paths is a bit scary, but
replacing the check with reject on '..' seems to work.

please correct me if i'm wrong and this is insecure.
la_ninpre 6 maanden geleden
bovenliggende
commit
2f0f3d45f4
2 gewijzigde bestanden met toevoegingen van 2 en 2 verwijderingen
  1. 1 1
      data.c
  2. 1 1
      html.c

+ 1 - 1
data.c

@@ -2691,7 +2691,7 @@ static int _load_raw_file(const char *fn, xs_val **data, int *size,
 xs_str *_static_fn(snac *snac, const char *id)
 /* gets the filename for a static file */
 {
-    if (strchr(id, '/'))
+    if (strstr(id, ".."))
         return NULL;
     else
         return xs_fmt("%s/static/%s", snac->basedir, id);

+ 1 - 1
html.c

@@ -5026,7 +5026,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
     }
     else
     if (xs_startswith(p_path, "s/")) { /** a static file **/
-        xs *l    = xs_split(p_path, "/");
+        xs *l    = xs_split_n(p_path, "/", 1);
         const char *id = xs_list_get(l, 1);
         int sz;