Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 4415850

Browse files
authored
fix(deps): update to restify 7.1 and mysql 2.15 (#351), r=@rfk
1 parent 5a27b0a commit 4415850

File tree

7 files changed

+238
-296
lines changed

7 files changed

+238
-296
lines changed

.nsprc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"exceptions": [
3-
// mysql
4-
"https://nodesecurity.io/advisories/602",
5-
// tunnel-agent
6-
"https://nodesecurity.io/advisories/598"
7-
]
2+
"exceptions": []
83
}

db-server/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
var restify = require('restify')
6-
var safeJsonFormatter = require('restify-safe-json-formatter')
76
var bufferize = require('./lib/bufferize')
87
var version = require('../package.json').version
98
var errors = require('./lib/error')
9+
const safeJsonFormatter = require('./lib/safeJsonFormatter')
1010

1111
function createServer(db) {
1212

@@ -47,13 +47,14 @@ function createServer(db) {
4747
})
4848
}
4949

50-
var api = restify.createServer({
50+
const api = restify.createServer({
5151
formatters: {
5252
'application/json; q=0.9': safeJsonFormatter
5353
}
5454
})
55-
api.use(restify.bodyParser())
56-
api.use(restify.queryParser())
55+
56+
api.use(restify.plugins.bodyParser())
57+
api.use(restify.plugins.queryParser())
5758
api.use(bufferize.bufferizeRequest.bind(null, new Set([
5859
// These are all the different params that we handle as binary Buffers,
5960
// but are passed into the API as hex strings.
@@ -266,6 +267,13 @@ function createServer(db) {
266267
res.send(result.map(bufferize.unbuffer))
267268
}
268269
else {
270+
271+
// When performing a `HEAD` request, the content type is not
272+
// set, manually set to application/json
273+
if (req.method === 'HEAD') {
274+
res.setHeader('Content-Type', 'application/json')
275+
}
276+
269277
res.send(bufferize.unbuffer(result || {}))
270278
}
271279
}

db-server/lib/safeJsonFormatter.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
module.exports = (req, res, body) => {
6+
let data = body ? JSON.stringify(body) : 'null'
7+
data = data.replace(/</g, '\\u003c')
8+
.replace(/>/g, '\\u003e')
9+
.replace(/&/g, '\\u0026')
10+
11+
res.setHeader('Content-Length', Buffer.byteLength(data))
12+
return data
13+
}

db-server/test/client-then.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Any copyright is dedicated to the Public Domain.
22
* http://creativecommons.org/publicdomain/zero/1.0/ */
33

4-
var restify = require('restify')
4+
const clients = require('restify-clients')
55
var P = require('../../lib/promise')
66

77
var ops = [ 'head', 'get', 'post', 'put', 'del' ]
@@ -11,7 +11,7 @@ module.exports = function createClient(cfg) {
1111
cfg.headers = {
1212
connection : 'close',
1313
}
14-
var client = restify.createJsonClient(cfg)
14+
const client = clients.createJsonClient(cfg)
1515

1616
// create a thenable version of each operation
1717
ops.forEach(function(name) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
* http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
'use strict'
5+
6+
const assert = require('insist')
7+
const safeJsonFormatter = require('../../lib/safeJsonFormatter')
8+
9+
describe('safeJsonFormatter module', () => {
10+
it('safeJsonFormatter function exported', () => {
11+
assert.equal(typeof safeJsonFormatter === 'function', true)
12+
})
13+
14+
it('escapes input', () => {
15+
const req = {}
16+
const res = {
17+
setHeader: () => {
18+
}
19+
}
20+
const body = {'foo': '<script>&'}
21+
const expectedData = '{"foo":"\\u003cscript\\u003e\\u0026"}'
22+
const data = safeJsonFormatter(req, res, body)
23+
assert.equal(data, expectedData, 'script is escaped')
24+
})
25+
})

0 commit comments

Comments
 (0)