mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2026-10-12 02:12:31 +00:00
[bot-detection] drop the URI from the cookie (#4656)
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/appsec/challenge/pb"
|
||||
)
|
||||
|
||||
func TestHasLeadingZeroBits(t *testing.T) {
|
||||
@@ -525,10 +527,31 @@ func TestValidateChallengeResponse_FingerprintRoundTrip(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, cd)
|
||||
assert.Equal(t, submitted.FSID, cd.Fingerprint.FSID)
|
||||
assert.Equal(t, submitted.URL, cd.Fingerprint.URL)
|
||||
// URL intentionally dropped to save space.
|
||||
assert.Empty(t, cd.Fingerprint.URL)
|
||||
assert.Equal(t, c.powDifficulty, cd.PowDifficulty)
|
||||
}
|
||||
|
||||
// fpscanner reports window.location.href, so the URL is site-controlled and
|
||||
// unbounded. It used to be sealed into the cookie, and a long enough query
|
||||
// string pushed the envelope past the size browsers guarantee: the seal failed
|
||||
// and the visitor could never pass the challenge.
|
||||
func TestSealCookieWithOversizedFingerprintURL(t *testing.T) {
|
||||
fp := FingerprintData{
|
||||
FSID: "FS1_00001000000000_00010h02ba",
|
||||
URL: "https://example.com/landing?utm=" + strings.Repeat("x", 8000),
|
||||
}
|
||||
|
||||
key := make([]byte, 32)
|
||||
|
||||
encoded, err := sealCookieV0(&pb.ChallengeCookie{
|
||||
Fingerprint: fp.ToProto(),
|
||||
PowDifficulty: PowDifficultyMedium,
|
||||
}, key, time.Now().Add(time.Hour).Unix(), 0, "", []byte("ua"), MaxCookieLen)
|
||||
require.NoError(t, err)
|
||||
assert.LessOrEqual(t, len(encoded), MaxCookieLen)
|
||||
}
|
||||
|
||||
func TestValidateChallengeResponse_MultipleConcurrentClients(t *testing.T) {
|
||||
c := newTestRuntimeWithDifficulty(8)
|
||||
|
||||
|
||||
@@ -332,10 +332,11 @@ func (f *FingerprintData) ToProto() *pb.FingerprintData {
|
||||
Locale: f.Signals.Locale.toProto(),
|
||||
Contexts: f.Signals.Contexts.toProto(),
|
||||
},
|
||||
Fsid: f.FSID,
|
||||
Nonce: f.Nonce,
|
||||
Time: f.Time,
|
||||
Url: f.URL,
|
||||
Fsid: f.FSID,
|
||||
Nonce: f.Nonce,
|
||||
Time: f.Time,
|
||||
// Url is deliberately not carried: fpscanner report window.location.href.
|
||||
// It can be big and it ain't useful to us outside on_challenge_submit.
|
||||
FastBotDetection: bool(f.FastBotDetection),
|
||||
FastBotDetectionDetails: f.FastBotDetectionDetails.toProto(),
|
||||
Bot: f.Bot.toProto(),
|
||||
|
||||
Reference in New Issue
Block a user