Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent pixel flood attacks #254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package imageproxy

import (
"bytes"
"errors"
"fmt"
"image"
_ "image/gif" // register gif format
Expand Down Expand Up @@ -54,6 +55,18 @@ func Transform(img []byte, opt Options) ([]byte, error) {
return img, nil
}

// decode image metadata
imageMeta, _, err := image.DecodeConfig(bytes.NewReader(img))
if err != nil {
return nil, err
}

// prevent pixel flooding attacks
// accept no larger than a 10,000 x 10,000 image
if imageMeta.Width*imageMeta.Height > 100000000 {
return nil, errors.New("image too large")
}

// decode image
m, format, err := image.Decode(bytes.NewReader(img))
if err != nil {
Expand Down
Loading