Skip to content

Commit 1ed9ff2

Browse files
author
Rui Marinho
committed
Update cookie detection
Instead of looking at `req.cookies`, the parser will only detect cookies set in headers because ultimately that is where middleware originally grabs the information from. This results in a much simplified logic.
1 parent 5e7797a commit 1ed9ff2

File tree

3 files changed

+13
-67
lines changed

3 files changed

+13
-67
lines changed

lib/parsers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
112112
// cookies:
113113
//
114114
// node: req.headers.cookie
115-
// express: req.cookies (expressjs/cookies)
115+
// express: req.headers.cookie
116116
// koa: req.headers.cookie
117117
//
118-
var cookies = (isPlainObject(req.cookies) ? req.cookies : '' ) || cookie.parse(headers.cookie || headers.cookies || '');
118+
var cookies = cookie.parse(headers.cookie || '');
119119

120120
// body data:
121121
//

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
},
2626
"dependencies": {
2727
"cookie": "0.1.0",
28-
"lodash._shimisplainobject": "^2.4.1",
2928
"lsmod": "~0.0.3",
3029
"node-uuid": "~1.4.1",
3130
"stack-trace": "0.0.7"
3231
},
3332
"devDependencies": {
34-
"mocha": "*",
35-
"should": "~3.3.1",
36-
"nock": "*",
33+
"coffee-script": "~1.7.1",
3734
"glob": "*",
35+
"mocha": "*",
3836
"mock-udp": "*",
39-
"coffee-script": "~1.7.1"
37+
"nock": "*",
38+
"should": "~3.3.1"
4039
},
4140
"optionalDependencies": {
4241
"connect": "*",
43-
"express": "*"
42+
"express": "*",
43+
"koa": "*"
4444
}
4545
}

test/raven.parsers.js

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var assert = require('assert');
22
var raven = require('../');
3-
var client = new raven.Client()
3+
var client = new raven.Client();
4+
45
raven.parsers = require('../lib/parsers');
56

67
describe('raven.parsers', function(){
@@ -176,22 +177,6 @@ describe('raven.parsers', function(){
176177
});
177178

178179
describe('`cookie` detection', function() {
179-
it('should parse `req.cookies`', function(){
180-
var mockReq = {
181-
method: 'GET',
182-
url: '/some/path?key=value',
183-
headers: {
184-
host: 'mattrobenolt.com',
185-
},
186-
cookies: {
187-
foo: 'bar'
188-
}
189-
};
190-
191-
var parsed = raven.parsers.parseRequest(mockReq);
192-
parsed['sentry.interfaces.Http'].cookies.should.eql({ foo: 'bar' });
193-
});
194-
195180
it('should parse `req.headers.cookie`', function(){
196181
var mockReq = {
197182
method: 'GET',
@@ -206,59 +191,20 @@ describe('raven.parsers', function(){
206191
parsed['sentry.interfaces.Http'].cookies.should.eql({ foo: 'bar' });
207192
});
208193

209-
it('should parse `req.headers.cookies`', function(){
194+
it('should parse `req.header.cookie`', function(){
210195
var mockReq = {
211196
method: 'GET',
212197
url: '/some/path?key=value',
213-
headers: {
214-
host: 'mattrobenolt.com',
215-
cookies: 'qux=foo'
216-
}
217-
};
218-
219-
var parsed = raven.parsers.parseRequest(mockReq);
220-
parsed['sentry.interfaces.Http'].cookies.should.eql({ qux: 'foo' });
221-
});
222-
223-
it('should parse `req.cookies`', function(){
224-
var mockReq = {
225-
method: 'GET',
226-
url: '/some/path?key=value',
227-
headers: {
198+
header: {
228199
host: 'mattrobenolt.com',
229-
},
230-
cookies: {
231-
foo: 'bar'
200+
cookie: 'foo=bar'
232201
}
233202
};
234203

235204
var parsed = raven.parsers.parseRequest(mockReq);
236205
parsed['sentry.interfaces.Http'].cookies.should.eql({ foo: 'bar' });
237206
});
238207

239-
it('should fallback to `req.headers.cookies` if `req.cookies` is not a plain object', function(){
240-
var cookie = function Cookie(name, value) {
241-
this.name = name;
242-
this.value = value;
243-
};
244-
245-
var cookies = function Cookies() {
246-
this.cookies = [new Cookie('foo', 'bar')];
247-
};
248-
249-
var mockReq = {
250-
method: 'GET',
251-
url: '/some/path?key=value',
252-
headers: {
253-
host: 'mattrobenolt.com',
254-
cookie: 'qux=baz'
255-
},
256-
cookies: cookies
257-
};
258-
259-
var parsed = raven.parsers.parseRequest(mockReq);
260-
parsed['sentry.interfaces.Http'].cookies.should.eql({ qux: 'baz' });
261-
});
262208
});
263209

264210
describe('`query` detection', function() {

0 commit comments

Comments
 (0)