mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-28 23:37:41 +00:00
Add BackendVerifyFails to /stats to count request spam
This commit is contained in:
parent
38972364fb
commit
6f13ea360c
2 changed files with 7 additions and 4 deletions
|
@ -46,6 +46,8 @@ type StatsData struct {
|
||||||
|
|
||||||
EmotesReportedTotal uint64
|
EmotesReportedTotal uint64
|
||||||
|
|
||||||
|
BackendVerifyFails uint64
|
||||||
|
|
||||||
// DisconnectReasons is at the bottom because it has indeterminate size
|
// DisconnectReasons is at the bottom because it has indeterminate size
|
||||||
DisconnectReasons map[string]uint64
|
DisconnectReasons map[string]uint64
|
||||||
}
|
}
|
||||||
|
@ -57,7 +59,7 @@ type StatsData struct {
|
||||||
// I don't really care.
|
// I don't really care.
|
||||||
var Statistics = newStatsData()
|
var Statistics = newStatsData()
|
||||||
|
|
||||||
const StatsDataVersion = 4
|
const StatsDataVersion = 5
|
||||||
const pageSize = 4096
|
const pageSize = 4096
|
||||||
|
|
||||||
var cpuUsage struct {
|
var cpuUsage struct {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"golang.org/x/crypto/nacl/box"
|
"golang.org/x/crypto/nacl/box"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -70,9 +69,11 @@ func UnsealRequest(form url.Values) (url.Values, error) {
|
||||||
dec := base64.NewDecoder(base64.URLEncoding, strings.NewReader(nonceString))
|
dec := base64.NewDecoder(base64.URLEncoding, strings.NewReader(nonceString))
|
||||||
count, err := dec.Read(nonce[:])
|
count, err := dec.Read(nonce[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Statistics.BackendVerifyFails++
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if count != 24 {
|
if count != 24 {
|
||||||
|
Statistics.BackendVerifyFails++
|
||||||
return nil, ErrorShortNonce
|
return nil, ErrorShortNonce
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,13 +84,13 @@ func UnsealRequest(form url.Values) (url.Values, error) {
|
||||||
|
|
||||||
message, ok := box.OpenAfterPrecomputation(nil, cipherBuffer.Bytes(), &nonce, &backendSharedKey)
|
message, ok := box.OpenAfterPrecomputation(nil, cipherBuffer.Bytes(), &nonce, &backendSharedKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Statistics.BackendVerifyFails++
|
||||||
return nil, ErrorInvalidSignature
|
return nil, ErrorInvalidSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
retValues, err := url.ParseQuery(string(message))
|
retValues, err := url.ParseQuery(string(message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Assume that the signature was accidentally correct but the contents were garbage
|
Statistics.BackendVerifyFails++
|
||||||
log.Println("Error unsealing request:", err)
|
|
||||||
return nil, ErrorInvalidSignature
|
return nil, ErrorInvalidSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue