You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When verifying the validity of object parameters, gojsonschema will checked all of the parameters, one by one check every regular expression matching on it self parameter. Only After the check is complete, gojsonschema checks whether the number of parameters exceeds the maximum value specified by maxItems.
eg:When a list with 1000000 members is transferred, although the maximum number of parameters is set to 2, the system verifies the 1 million parameters one by one. In this process, a DoS vulnerability occurs and the system determines whether the total number of parameters exceeds the value of maxItems.
In the actual verification process, when attacker send the list parameters contains one million members for my api, only need 20 concurrent requests are required, my CPU had BOOM and my web service had Denial of service.
The text was updated successfully, but these errors were encountered:
num := 1000000 // The number of parameters from attacker input
var data = fmt.Sprintf(`[%s"a"]`, strings.Repeat(`"1",`, num))
if !validate(Obj, data) {
fmt.Println("error!")
} else {
fmt.Println("OK!")
}
}
// verifying the validity of object parameters
func validate(Obj map[string]interface{}, data string) bool {
ObjArr, err := json.Marshal(Obj)
if err != nil {
return false
}
ObjLoader := gojsonschema.NewStringLoader(string(ObjArr))
dataLoader := gojsonschema.NewStringLoader(data)
validateResult, _ := gojsonschema.Validate(ObjLoader, dataLoader)
if !validateResult.Valid() {
for _, desc := range validateResult.Errors() {
log.Printf("- %s\n", desc.String())
}
return false
} else {
return true
}
}
This library is used in many projects to check API parameters. I suggest adding a switch to exit and return false if it fails once.
Defend against network attacks from DOS
When verifying the validity of object parameters, gojsonschema will checked all of the parameters, one by one check every regular expression matching on it self parameter. Only After the check is complete, gojsonschema checks whether the number of parameters exceeds the maximum value specified by maxItems.
eg:When a list with 1000000 members is transferred, although the maximum number of parameters is set to 2, the system verifies the 1 million parameters one by one. In this process, a DoS vulnerability occurs and the system determines whether the total number of parameters exceeds the value of maxItems.
In the actual verification process, when attacker send the list parameters contains one million members for my api, only need 20 concurrent requests are required, my CPU had BOOM and my web service had Denial of service.
The text was updated successfully, but these errors were encountered: