Skip to content

Commit 4882c0f

Browse files
committed
Fix XSS based prototype solution on Segment.io
1 parent 7ca3cd7 commit 4882c0f

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

integrations/segmentio/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var localstorage = require('yields-store');
1515
var protocol = require('@segment/protocol');
1616
var send = require('@segment/send-json');
1717
var topDomain = require('@segment/top-domain');
18-
var utm = require('@segment/utm-params');
18+
var utm = require('./utm');
1919
var uuid = require('uuid').v4;
2020
var Queue = require('@segment/localstorage-retry');
2121

integrations/segmentio/lib/utm.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function utm(query) {
2+
// Polyfills
3+
if (!String.prototype.startsWith) {
4+
Object.defineProperty(String.prototype, 'startsWith', {
5+
value: function (search, rawPos) {
6+
var pos = rawPos > 0 ? rawPos | 0 : 0
7+
return this.substring(pos, pos + search.length) === search
8+
}
9+
})
10+
}
11+
12+
if (!String.prototype.includes) {
13+
String.prototype.includes = function (search, start) {
14+
'use strict'
15+
16+
if (search instanceof RegExp) {
17+
throw TypeError('first argument must not be a RegExp')
18+
}
19+
if (start === undefined) { start = 0 }
20+
return this.indexOf(search, start) !== -1
21+
}
22+
}
23+
24+
if (query.startsWith('?')) {
25+
query = query.substring(1)
26+
}
27+
query = query.replace(/\?/g, '&')
28+
29+
return query.split('&').reduce((acc, str) => {
30+
var k = str.split('=')[0]
31+
var v = str.split('=')[1]
32+
33+
if (k.includes('utm_')) {
34+
var utmParam = k.substr(4)
35+
if (utmParam === 'campaign') {
36+
utmParam = 'name'
37+
}
38+
acc[utmParam] = v
39+
}
40+
return acc
41+
})
42+
}
43+
44+
module.exports = utm

integrations/segmentio/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-segmentio",
33
"description": "The Segmentio analytics.js integration.",
4-
"version": "4.4.1",
4+
"version": "4.4.2",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",
@@ -32,7 +32,6 @@
3232
"@segment/protocol": "^1.0.0",
3333
"@segment/send-json": "^3.0.0",
3434
"@segment/top-domain": "^3.0.0",
35-
"@segment/utm-params": "^2.0.0",
3635
"component-clone": "^0.2.2",
3736
"component-cookie": "^1.1.2",
3837
"component-type": "^1.2.1",

yarn.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,14 +2280,6 @@
22802280
resolved "https://registry.yarnpkg.com/@segment/trample/-/trample-0.2.0.tgz#5b141159f67b06efaa295d2ebe240b51096134c5"
22812281
integrity sha1-WxQRWfZ7Bu+qKV0uviQLUQlhNMU=
22822282

2283-
"@segment/utm-params@^2.0.0":
2284-
version "2.0.0"
2285-
resolved "https://registry.yarnpkg.com/@segment/utm-params/-/utm-params-2.0.0.tgz#fea3c8a92bfba0d69e861fb3b26d7d882f139334"
2286-
integrity sha1-/qPIqSv7oNaehh+zsm19iC8TkzQ=
2287-
dependencies:
2288-
"@ndhoule/foldl" "^2.0.1"
2289-
component-querystring "^2.0.0"
2290-
22912283
"@sinonjs/commons@^1", "@sinonjs/commons@^1.0.2", "@sinonjs/commons@^1.4.0":
22922284
version "1.4.0"
22932285
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.4.0.tgz#7b3ec2d96af481d7a0321252e7b1c94724ec5a78"
@@ -6526,7 +6518,7 @@ extend@3.0.1:
65266518
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
65276519
integrity sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=
65286520

6529-
extend@3.0.2, extend@^3.0.0, extend@^3.0.1, extend@^3.0.2, extend@~3.0.2:
6521+
extend@3.0.2, extend@^3.0.0, extend@^3.0.2, extend@~3.0.2:
65306522
version "3.0.2"
65316523
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
65326524
integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==

0 commit comments

Comments
 (0)