forked from TrueCloudLab/frostfs-s3-gw
[#619] Fix content-length invalid check
Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
711d6b2c71
commit
bfec3e0a5e
2 changed files with 117 additions and 7 deletions
|
@ -54,17 +54,29 @@ func (p *postPolicy) condition(key string) *policyCondition {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *postPolicy) CheckContentLength(size uint64) bool {
|
||||
func (p *postPolicy) CheckContentLength(size uint64) error {
|
||||
if p.empty {
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
for _, condition := range p.Conditions {
|
||||
if condition.Matching == "content-length-range" {
|
||||
length := strconv.FormatUint(size, 10)
|
||||
return condition.Key <= length && length <= condition.Value
|
||||
start, err := strconv.ParseUint(condition.Key, 10, 64)
|
||||
if err != nil {
|
||||
return errInvalidCondition
|
||||
}
|
||||
|
||||
end, err := strconv.ParseUint(condition.Value, 10, 64)
|
||||
if err != nil {
|
||||
return errInvalidCondition
|
||||
}
|
||||
|
||||
if start <= size && size <= end {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("length of the content did not fall within the range specified in the condition")
|
||||
}
|
||||
}
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *policyCondition) match(value string) bool {
|
||||
|
@ -560,8 +572,8 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !policy.CheckContentLength(size) {
|
||||
h.logAndSendError(ctx, w, "invalid content-length", reqInfo, apierr.GetAPIError(apierr.ErrInvalidArgument))
|
||||
if err := policy.CheckContentLength(size); err != nil {
|
||||
h.logAndSendError(ctx, w, err.Error(), reqInfo, apierr.GetAPIError(apierr.ErrPostPolicyConditionInvalidFormat))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue