Skip to content

Commit

Permalink
privacy: Add tests to illustrate JSON injection bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
djcsdy committed May 17, 2020
1 parent fa02275 commit 255fc04
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
37 changes: 37 additions & 0 deletions privacy/ccpa/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions privacy/gdpr/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 255fc04

Please sign in to comment.