mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
Add content length cap for paste creation endpoint (#8)
* add content length cap * add development docker compose stack * Fix paste creation error notification data * Add length cap to hastebin endpoint as well * Mention length cap in Readme Co-authored-by: Lukas Schulte Pelkum <kbrt@protonmail.com>
This commit is contained in:
@@ -13,6 +13,14 @@ import (
|
||||
|
||||
// HastebinSupportHandler handles the legacy hastebin requests
|
||||
func HastebinSupportHandler(ctx *fasthttp.RequestCtx) {
|
||||
// Check content length before reading body into memory
|
||||
if config.Current.LengthCap > 0 &&
|
||||
ctx.Request.Header.ContentLength() > config.Current.LengthCap {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
ctx.SetBodyString("request body length overflow")
|
||||
return
|
||||
}
|
||||
|
||||
// Define the paste content
|
||||
var content string
|
||||
switch string(ctx.Request.Header.ContentType()) {
|
||||
|
@@ -51,6 +51,14 @@ func v1GetPaste(ctx *fasthttp.RequestCtx) {
|
||||
|
||||
// v1PostPaste handles the 'POST /v1/pastes' endpoint
|
||||
func v1PostPaste(ctx *fasthttp.RequestCtx) {
|
||||
// Check content length before reading body into memory
|
||||
if config.Current.LengthCap > 0 &&
|
||||
ctx.Request.Header.ContentLength() > config.Current.LengthCap {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
ctx.SetBodyString("request body length overflow")
|
||||
return
|
||||
}
|
||||
|
||||
// Unmarshal the body
|
||||
values := make(map[string]string)
|
||||
err := json.Unmarshal(ctx.PostBody(), &values)
|
||||
|
Reference in New Issue
Block a user