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

Commit

Permalink
fix(push): reject extra push-payloads properties instead of removing …
Browse files Browse the repository at this point in the history
…them
  • Loading branch information
eoger committed Mar 21, 2017
1 parent c77df31 commit c90719a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
24 changes: 16 additions & 8 deletions docs/pushpayloads.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
"type":"string",
"description":"The name of the device who joined this account"
}
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"deviceDisconnected":{
"required":[
Expand Down Expand Up @@ -69,9 +71,11 @@
"type":"string",
"description":"The id of the device who was disconnected remotely"
}
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"collectionsChanged":{
"required":[
Expand Down Expand Up @@ -105,9 +109,11 @@
"tabs", "passwords", "clients" ]
}
}
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"passwordChanged":{
"required":[
Expand All @@ -124,7 +130,8 @@
"fxaccounts:password_changed"
]
}
}
},
"additionalProperties": false
},
"passwordReset":{
"required":[
Expand All @@ -141,7 +148,8 @@
"fxaccounts:password_reset"
]
}
}
},
"additionalProperties": false
}
}
}
2 changes: 1 addition & 1 deletion lib/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var MS_ONE_MONTH = MS_ONE_DAY * 30

var path = require('path')
var Ajv = require('ajv')
var ajv = new Ajv({ removeAdditional: 'all' })
var ajv = new Ajv()
var fs = require('fs')
var butil = require('../crypto/butil')
var userAgent = require('../userAgent')
Expand Down
17 changes: 7 additions & 10 deletions test/local/routes/account_devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('/account/devices/notify', function () {
})
})

it('extra push payload properties are stripped', function () {
it('extra push payload properties are rejected', function () {
var extraPropsPayload = JSON.parse(JSON.stringify(pushPayload))
extraPropsPayload.extra = true
extraPropsPayload.data.extra = true
Expand All @@ -271,14 +271,12 @@ describe('/account/devices/notify', function () {
pushToAllDevicesPromise.resolve()
return Promise.resolve()
})
return runTest(route, mockRequest, function (response) {
return pushToAllDevicesPromise.promise.then(function () {
assert.deepEqual(mockPush.pushToAllDevices.args[0][2], {
data: Buffer.from(JSON.stringify(pushPayload)),
excludedDeviceIds: ['bogusid'],
TTL: 60
}, 'third argument payload properties has no extra properties')
})
return runTest(route, mockRequest, function () {
assert(false, 'should have thrown')
})
.then(() => assert.ok(false), function (err) {
assert.equal(err.output.statusCode, 400, 'correct status code is returned')
assert.equal(err.errno, error.ERRNO.INVALID_PARAMETER, 'correct errno is returned')
})
})

Expand Down Expand Up @@ -334,7 +332,6 @@ describe('/account/devices/notify', function () {
to: ['bogusid1', 'bogusid2'],
TTL: 60,
payload: {
isValid: true,
version: 1,
command: 'fxaccounts:password_reset'
}
Expand Down

0 comments on commit c90719a

Please sign in to comment.