Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
stricter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Zeug committed Mar 31, 2017
1 parent 1cb0f5c commit 8d9ee17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/ipc/ipcProviderBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Windows = require('../windows');


const ERRORS = {
INVALID_PAYLOAD: { code: -32600, message: 'Payload, or some of its content properties are invalid. Please check if they are valid HEX.' },
INVALID_PAYLOAD: { code: -32600, message: 'Payload, or some of its content properties are invalid. Please check if they are valid HEX with \'0x\' prefix.' },
METHOD_DENIED: { code: -32601, message: "Method \'__method__\' not allowed." },
METHOD_TIMEOUT: { code: -32603, message: "Request timed out for method \'__method__\'." },
TX_DENIED: { code: -32603, message: 'Transaction denied' },
Expand Down
11 changes: 5 additions & 6 deletions modules/ipc/methods/eth_sendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ module.exports = class extends BaseProcessor {
try {
_.each(payload.params[0], (val, key) => {
// if doesn't have hex then leave
if (_.isString(val) || _.isNumber(val)) {

if (!_.isString(val)) {
throw this.ERRORS.INVALID_PAYLOAD;
} else {
// make sure all data is lowercase and has 0x
if (val) val = `0x${val.toLowerCase().replace('0x', '')}`;
if (val) val = `0x${val.toLowerCase().replace(/^0x/igm, '')}`;

if (val.match(/[^0-9a-fx]/igm)) {
if (val.substr(2).match(/[^0-9a-f]/igm)) {
throw this.ERRORS.INVALID_PAYLOAD;
}
} else {
throw this.ERRORS.INVALID_PAYLOAD;
}

payload.params[0][key] = val;
Expand Down

0 comments on commit 8d9ee17

Please sign in to comment.