Skip to content

Commit be32328

Browse files
BennyThinkn0vad3v
andauthored
Fix Malformed dir traversal (#331)
* Directory traversal with malformed HTTP request #330 * bump version * also %2e * Use prefix to check invalid Path --------- Co-authored-by: n0vad3v <n0vad3v@riseup.net>
1 parent c7bebfc commit be32328

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var (
5050
ProxyMode bool
5151
Prefetch bool
5252
Config = NewWebPConfig()
53-
Version = "0.11.2"
53+
Version = "0.11.3"
5454
WriteLock = cache.New(5*time.Minute, 10*time.Minute)
5555
ConvertLock = cache.New(5*time.Minute, 10*time.Minute)
5656
RemoteRaw = "./remote-raw"

handler/router.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ func Convert(c *fiber.Ctx) error {
2222
// 2. generate rawImagePath, could be local path or remote url(possible with query string)
2323
// 3. pass it to encoder, get the result, send it back
2424

25+
// normal http request will start with /
26+
if !strings.HasPrefix(c.Path(), "/") {
27+
_ = c.SendStatus(http.StatusBadRequest)
28+
return nil
29+
}
30+
2531
var (
2632
reqHostname = c.Hostname()
2733
reqHost = c.Protocol() + "://" + reqHostname // http://www.example.com:8000

0 commit comments

Comments
 (0)