From 255fc0455e3da6569fc89493ce76a1d7277738cd Mon Sep 17 00:00:00 2001 From: Daniel Cassidy Date: Sun, 17 May 2020 17:39:41 +0100 Subject: [PATCH] privacy: Add tests to illustrate JSON injection bug. --- privacy/ccpa/policy_test.go | 37 +++++++++++++++++++++++++++++++++++++ privacy/gdpr/policy_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/privacy/ccpa/policy_test.go b/privacy/ccpa/policy_test.go index 54613c89880..740f95a8a6a 100644 --- a/privacy/ccpa/policy_test.go +++ b/privacy/ccpa/policy_test.go @@ -71,6 +71,17 @@ func TestRead(t *testing.T) { }, expectedError: true, }, + { + description: "Injection Attack", + request: &openrtb.BidRequest{ + Regs: &openrtb.Regs{ + Ext: json.RawMessage(`{"us_privacy":"1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }, + }, + expectedPolicy: Policy{ + Value: "1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\"", + }, + }, } for _, test := range testCases { @@ -138,6 +149,32 @@ func TestWrite(t *testing.T) { Ext: json.RawMessage(`malformed`)}}, expectedError: true, }, + { + description: "Injection Attack With Nil Request Regs Object", + policy: Policy{Value: "1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}, + request: &openrtb.BidRequest{}, + expected: &openrtb.BidRequest{Regs: &openrtb.Regs{ + Ext: json.RawMessage(`{"us_privacy":"1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }}, + }, + { + description: "Injection Attack With Nil Request Regs Ext Object", + policy: Policy{Value: "1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}, + request: &openrtb.BidRequest{Regs: &openrtb.Regs{}}, + expected: &openrtb.BidRequest{Regs: &openrtb.Regs{ + Ext: json.RawMessage(`{"us_privacy":"1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }}, + }, + { + description: "Injection Attack With Existing Request Regs Ext Object", + policy: Policy{Value: "1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}, + request: &openrtb.BidRequest{Regs: &openrtb.Regs{ + Ext: json.RawMessage(`{"existing":"any"}`), + }}, + expected: &openrtb.BidRequest{Regs: &openrtb.Regs{ + Ext: json.RawMessage(`{"existing":"any","us_privacy":"1YYY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }}, + }, } for _, test := range testCases { diff --git a/privacy/gdpr/policy_test.go b/privacy/gdpr/policy_test.go index 00b97644971..76b0686fb52 100644 --- a/privacy/gdpr/policy_test.go +++ b/privacy/gdpr/policy_test.go @@ -59,6 +59,32 @@ func TestWrite(t *testing.T) { Ext: json.RawMessage(`malformed`)}}, expectedError: true, }, + { + description: "Injection Attack With Nil Request User Object", + policy: Policy{Consent: "BONV8oqONXwgmADACHENAO7pqzAAppY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}, + request: &openrtb.BidRequest{}, + expected: &openrtb.BidRequest{User: &openrtb.User{ + Ext: json.RawMessage(`{"consent":"BONV8oqONXwgmADACHENAO7pqzAAppY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }}, + }, + { + description: "Injection Attack With Nil Request User Ext Object", + policy: Policy{Consent: "BONV8oqONXwgmADACHENAO7pqzAAppY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}, + request: &openrtb.BidRequest{User: &openrtb.User{}}, + expected: &openrtb.BidRequest{User: &openrtb.User{ + Ext: json.RawMessage(`{"consent":"BONV8oqONXwgmADACHENAO7pqzAAppY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }}, + }, + { + description: "Injection Attack With Existing Request User Ext Object", + policy: Policy{Consent: "BONV8oqONXwgmADACHENAO7pqzAAppY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}, + request: &openrtb.BidRequest{User: &openrtb.User{ + Ext: json.RawMessage(`{"existing":"any"}`), + }}, + expected: &openrtb.BidRequest{User: &openrtb.User{ + Ext: json.RawMessage(`{"existing":"any","consent":"BONV8oqONXwgmADACHENAO7pqzAAppY\"},\"oops\":\"malicious\",\"p\":{\"p\":\""}`), + }}, + }, } for _, test := range testCases {