Skip to content

Commit e00eacf

Browse files
authored
1 parent 5ec58a8 commit e00eacf

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

attributioncode/validator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717

1818
// pre-compile regex
1919
var (
20-
mozillaOrg = regexp.MustCompile(`^https://www.mozilla.org/`)
21-
rtamo = regexp.MustCompile(`^rta:`)
20+
referrerAllowedforRTAMO = regexp.MustCompile(`^https://www\.(mozilla\.org|firefox\.com)/`)
21+
rtamo = regexp.MustCompile(`^rta:`)
2222
)
2323

2424
// Set to match https://searchfox.org/mozilla-central/rev/a92ed79b0bc746159fc31af1586adbfa9e45e264/browser/components/attribution/AttributionCode.jsm#24
@@ -208,11 +208,11 @@ func (v *Validator) Validate(code, sig, refererHeader string) (*Code, error) {
208208
}
209209

210210
if attributionCode.FromRTAMO() {
211-
refererMatch := mozillaOrg.MatchString(refererHeader)
211+
refererMatch := referrerAllowedforRTAMO.MatchString(refererHeader)
212212

213213
if !refererMatch {
214-
logEntry.WithField("referer", refererHeader).Error("RTAMO attribution does not have https://www.mozilla.org referer header")
215-
return nil, errors.New("RTAMO attribution does not have https://www.mozilla.org referer header")
214+
logEntry.WithField("referer", refererHeader).Error("Invalid referer header for RTAMO attribution")
215+
return nil, errors.New("Invalid referer header for RTAMO attribution")
216216
}
217217
}
218218

attributioncode/validator_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ func TestValidateAttributionCode(t *testing.T) {
9898
ExpectedClientID: "(not set)",
9999
ExpectedSessionID: "",
100100
},
101+
{
102+
// source=addons.mozilla.org&medium=referral&campaign=amo-fx-cta-3006&content=rta:e2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0&experiment=(not set)&variation=(not set)&ua=edge&visit_id=(not set)
103+
In: "c291cmNlPWFkZG9ucy5tb3ppbGxhLm9yZyZtZWRpdW09cmVmZXJyYWwmY2FtcGFpZ249YW1vLWZ4LWN0YS0zMDA2JmNvbnRlbnQ9cnRhOmUySTVaR0l4Tm1FMExUWmxaR010TkRkbFl5MWhNV1kwTFdJNE5qSTVNbVZrTWpFeFpIMCZleHBlcmltZW50PShub3Qgc2V0KSZ2YXJpYXRpb249KG5vdCBzZXQpJnVhPWVkZ2UmdmlzaXRfaWQ9KG5vdCBzZXQp",
104+
Out: "campaign%3Damo-fx-cta-3006%26content%3Drta%253Ae2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0%26dltoken%3D__DL_TOKEN__%26experiment%3D%2528not%2Bset%2529%26medium%3Dreferral%26source%3Daddons.mozilla.org%26ua%3Dedge%26variation%3D%2528not%2Bset%2529",
105+
RefererHeader: "https://www.firefox.com/",
106+
ExpectedClientID: "(not set)",
107+
ExpectedSessionID: "",
108+
},
109+
{
110+
// source=addons.mozilla.org&medium=referral&campaign=amo-fx-cta-3006&content=rta:e2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0&experiment=(not set)&variation=(not set)&ua=edge&visit_id=(not set)
111+
In: "c291cmNlPWFkZG9ucy5tb3ppbGxhLm9yZyZtZWRpdW09cmVmZXJyYWwmY2FtcGFpZ249YW1vLWZ4LWN0YS0zMDA2JmNvbnRlbnQ9cnRhOmUySTVaR0l4Tm1FMExUWmxaR010TkRkbFl5MWhNV1kwTFdJNE5qSTVNbVZrTWpFeFpIMCZleHBlcmltZW50PShub3Qgc2V0KSZ2YXJpYXRpb249KG5vdCBzZXQpJnVhPWVkZ2UmdmlzaXRfaWQ9KG5vdCBzZXQp",
112+
Out: "campaign%3Damo-fx-cta-3006%26content%3Drta%253Ae2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0%26dltoken%3D__DL_TOKEN__%26experiment%3D%2528not%2Bset%2529%26medium%3Dreferral%26source%3Daddons.mozilla.org%26ua%3Dedge%26variation%3D%2528not%2Bset%2529",
113+
RefererHeader: "https://www.firefox.com/test/other/paths",
114+
ExpectedClientID: "(not set)",
115+
ExpectedSessionID: "",
116+
},
101117
{
102118
// campaign=testcampaign&content=testcontent&experiment=exp1&medium=testmedium&source=mozilla.com&timestamp=1670358814&variation=var1&visit_id=vid
103119
In: "Y2FtcGFpZ249dGVzdGNhbXBhaWduJmNvbnRlbnQ9dGVzdGNvbnRlbnQmZXhwZXJpbWVudD1leHAxJm1lZGl1bT10ZXN0bWVkaXVtJnNvdXJjZT1tb3ppbGxhLmNvbSZ0aW1lc3RhbXA9MTY3MDM1ODgxNCZ2YXJpYXRpb249dmFyMSZ2aXNpdF9pZD12aWQ.",
@@ -225,10 +241,22 @@ func TestValidateAttributionCode(t *testing.T) {
225241
},
226242
{
227243
"c291cmNlPWFkZG9ucy5tb3ppbGxhLm9yZyZtZWRpdW09cmVmZXJyYWwmY2FtcGFpZ249YW1vLWZ4LWN0YS0zMDA2JmNvbnRlbnQ9cnRhOmUySTVaR0l4Tm1FMExUWmxaR010TkRkbFl5MWhNV1kwTFdJNE5qSTVNbVZrTWpFeFpIMCZleHBlcmltZW50PShub3Qgc2V0KSZ2YXJpYXRpb249KG5vdCBzZXQpJnVhPWVkZ2UmdmlzaXRfaWQ9KG5vdCBzZXQp", // source=addons.mozilla.org&medium=referral&campaign=amo-fx-cta-3006&content=rta:e2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0&experiment=(not set)&variation=(not set)&ua=edge&visit_id=(not set)
228-
"RTAMO attribution does not have https://www.mozilla.org referer header",
244+
"Invalid referer header for RTAMO attribution",
229245
"",
230246
"https://invalid-referer.fake",
231247
},
248+
{
249+
"c291cmNlPWFkZG9ucy5tb3ppbGxhLm9yZyZtZWRpdW09cmVmZXJyYWwmY2FtcGFpZ249YW1vLWZ4LWN0YS0zMDA2JmNvbnRlbnQ9cnRhOmUySTVaR0l4Tm1FMExUWmxaR010TkRkbFl5MWhNV1kwTFdJNE5qSTVNbVZrTWpFeFpIMCZleHBlcmltZW50PShub3Qgc2V0KSZ2YXJpYXRpb249KG5vdCBzZXQpJnVhPWVkZ2UmdmlzaXRfaWQ9KG5vdCBzZXQp", // source=addons.mozilla.org&medium=referral&campaign=amo-fx-cta-3006&content=rta:e2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0&experiment=(not set)&variation=(not set)&ua=edge&visit_id=(not set)
250+
"Invalid referer header for RTAMO attribution",
251+
"",
252+
"https://www-mozilla.org",
253+
},
254+
{
255+
"c291cmNlPWFkZG9ucy5tb3ppbGxhLm9yZyZtZWRpdW09cmVmZXJyYWwmY2FtcGFpZ249YW1vLWZ4LWN0YS0zMDA2JmNvbnRlbnQ9cnRhOmUySTVaR0l4Tm1FMExUWmxaR010TkRkbFl5MWhNV1kwTFdJNE5qSTVNbVZrTWpFeFpIMCZleHBlcmltZW50PShub3Qgc2V0KSZ2YXJpYXRpb249KG5vdCBzZXQpJnVhPWVkZ2UmdmlzaXRfaWQ9KG5vdCBzZXQp", // source=addons.mozilla.org&medium=referral&campaign=amo-fx-cta-3006&content=rta:e2I5ZGIxNmE0LTZlZGMtNDdlYy1hMWY0LWI4NjI5MmVkMjExZH0&experiment=(not set)&variation=(not set)&ua=edge&visit_id=(not set)
256+
"Invalid referer header for RTAMO attribution",
257+
"",
258+
"https://www-firefox.com",
259+
},
232260
}
233261
for _, c := range invalidCodes {
234262
_, err := v.Validate(c.In, c.Sig, c.RefererHeader)

stubservice/stubhandlers/stubhandler_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ func TestRedirectFull(t *testing.T) {
235235
ExpectedClientIDGA4: "some-client-id-for-ga4",
236236
ExpectedSessionID: "some-session-id",
237237
},
238+
{
239+
// Same as above with fxc as referer.
240+
AttributionCode: `campaign=fxa-cta-123&content=rta:value&medium=referral&source=addons.mozilla.org&visit_id=some-visit-id&client_id_ga4=some-client-id-for-ga4&session_id=some-session-id`,
241+
Referer: `https://www.firefox.com/`,
242+
ExpectedLocation: `/cdn/builds/rtamo-firefox-stub/en-US/win/`,
243+
ExpectedCode: `campaign%3Dfxa-cta-123%26content%3Drta%253Avalue%26dltoken%3D[\w\d-]+%26medium%3Dreferral%26source%3Daddons.mozilla.org`,
244+
ExpectedClientID: "some-visit-id",
245+
ExpectedClientIDGA4: "some-client-id-for-ga4",
246+
ExpectedSessionID: "some-session-id",
247+
},
238248
{
239249
// We expect no prefix because the attribution data is not related to
240250
// RTAMO.

0 commit comments

Comments
 (0)