Bug Fix: file system traversal bug where %2F is treated as /

This commit is contained in:
int 80h
2022-02-02 18:03:04 -05:00
parent 2eabc3e893
commit 406fea7b6c
4 changed files with 8 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -186,7 +186,7 @@ dependencies = [
[[package]] [[package]]
name = "gemserv" name = "gemserv"
version = "0.6.3" version = "0.6.4"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"log", "log",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "gemserv" name = "gemserv"
version = "0.6.3" version = "0.6.4"
authors = ["int 80h <int@80h.dev>"] authors = ["int 80h <int@80h.dev>"]
edition = "2018" edition = "2018"
description = "A gemini server" description = "A gemini server"

6
README
View File

@@ -57,7 +57,6 @@ Scripts have 5 seconds to complete or they will be terminated.
### CGI Environments ### CGI Environments
These variables are preset for you. If you need more you can define them in the These variables are preset for you. If you need more you can define them in the
config file under "cgienv" config file under "cgienv"
@@ -77,3 +76,8 @@ TLS variables
- TLS_CLIENT_HASH - TLS_CLIENT_HASH
- REMOTE_USER - REMOTE_USER
## Changelog
### [0.6.4] - 20220202
Fixed a file system traversal bug. All previous versions are unsafe.

View File

@@ -243,7 +243,7 @@ pub async fn handle_connection(mut con: conn::Connection, url: url::Url) -> Resu
} else { } else {
path.push(&con.srv.server.dir); path.push(&con.srv.server.dir);
if url.path() != "" || url.path() != "/" { if url.path() != "" || url.path() != "/" {
let decoded = util::url_decode(url.path().trim_start_matches('/').as_bytes()); let decoded = util::url_decode(url.path().as_bytes()).trim_start_matches('/').to_owned();
path.push(decoded); path.push(decoded);
} }
} }