diff --git a/Makefile b/Makefile index 88833f8..099d822 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # These are for both `run` (implicit) and `test` (explicit) -PATH_INFO ?= /static/fileserver.gr +PATH_INFO ?= /fileserver.gr X_MATCHED_ROUTE ?= /static/... BINDLE_SERVER_URL ?= http://localhost:8080/v1 diff --git a/README.md b/README.md index 9dd12fa..9b50c08 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,11 @@ SOFTWARE The fileserver took `/static/filserver.gr`, removed the `/static/` part from the front, and then loaded `fileserver.gr` from the directory mounted in the `modules.toml`. Note that any subdirectories are also served. So `/static/foo/bar` would translate to the path `foo/bar` inside of the WebAssembly module (which in the example above would fully resolve to "/path/to/fileserver/foo/bar"). +## Security Note + +The Wagi fileserver is designed to serve any file mounted in the volume. Do not mount a +volume that contains files you do not want served. + ## Code of Conduct This project has adopted the [Microsoft Open Source Code of diff --git a/fileserver.gr b/fileserver.gr index 433bbfb..810bc9e 100644 --- a/fileserver.gr +++ b/fileserver.gr @@ -8,7 +8,9 @@ import String from "string" import Mediatype from "./lib/mediatype" import Stringutil from "./lib/stringutil" -let serve = (path) => { +let serve = (abs_path) => { + // Trim the leading / + let path = String.slice(1, String.length(abs_path), abs_path) File.fdWrite(File.stderr, "Fileserver: Loading file ") File.fdWrite(File.stderr, path) File.fdWrite(File.stderr, "\n") @@ -45,14 +47,13 @@ let serve = (path) => { } let guestpath = (env) => { + + // Backward compat for an older version of Wagi that had PATH_INFO wrong. + // X_RELATIVE_PATH was removed before Wagi 0.4 match (Map.get("X_RELATIVE_PATH", env)) { - Some(p) => p, + Some(p) => String.concat("/", p), None => { - // Backwards compat until Wagi 0.1.0 is released - let req = Option.unwrap(Map.get("PATH_INFO", env)) - let matched = Option.unwrap(Map.get("X_MATCHED_ROUTE", env)) - let base = Stringutil.beforeLast("/...", matched) - String.slice(String.length(base) + 1, String.length(req), req) + Option.unwrap(Map.get("PATH_INFO", env)) } }