Skip to content

Commit

Permalink
* (Apollon77) update amazon-cookie library to work around amazon secu…
Browse files Browse the repository at this point in the history
…rity changes

* (Apollon77) Prevent crash on invalid data in request data (Sentry IOBROKER-ALEXA2-1A)
* (Apollon77) Make sure to handle invalid list responses correctly (Sentry IOBROKER-ALEXA2-1T)
  • Loading branch information
Apollon77 committed Jul 13, 2020
1 parent 3b83f9c commit 70732e0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 49 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Thank you for that work.

## Changelog:

### __WORK IN PROGRESS__
* (Apollon77) update amazon-cookie library to work around amazon security changes
* (Apollon77) Prevent crash on invalid data in request data (Sentry IOBROKER-ALEXA2-1A)
* (Apollon77) Make sure to handle invalid list responses correctly (Sentry IOBROKER-ALEXA2-1T)

### 3.2.2 (2020-06-17)
* (Apollon77) Optimize Request Handling to also Handle timeouts correctly
* (Apollon77) Increase timeouts for some Smart Home calls to 30s
Expand Down
64 changes: 37 additions & 27 deletions alexa-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,38 +799,48 @@ class AlexaRemote extends EventEmitter {
delete logOptions.headers.Referer;
delete logOptions.headers.Origin;
this._options.logger && this._options.logger('Alexa-Remote: Sending Request with ' + JSON.stringify(logOptions) + ((options.method === 'POST' || options.method === 'PUT' || options.method === 'DELETE') ? ' and data=' + flags.data : ''));

let req = https.request(options, (res) => {
let body = '';

res.on('data', (chunk) => {
body += chunk;
});
let req;
try {
req = https.request(options, (res) => {
let body = '';

res.on('end', () => {
let ret;

if (typeof callback === 'function') {
if (!body) { // Method 'DELETE' may return HTTP STATUS 200 without body
this._options.logger && this._options.logger('Alexa-Remote: Response: No body');
return typeof res.statusCode === 'number' && res.statusCode%100 === 2 ? callback(null, { 'success': true }) : callback(new Error('no body'), null);
}

try {
ret = JSON.parse(body);
} catch (e) {
this._options.logger && this._options.logger('Alexa-Remote: Response: No/Invalid JSON');
callback && callback (new Error('no JSON'), body);
res.on('data', (chunk) => {
body += chunk;
});

res.on('end', () => {
let ret;

if (typeof callback === 'function') {
if (!body) { // Method 'DELETE' may return HTTP STATUS 200 without body
this._options.logger && this._options.logger('Alexa-Remote: Response: No body');
return typeof res.statusCode === 'number' && res.statusCode % 100 === 2 ? callback(null, {'success': true}) : callback(new Error('no body'), null);
}

try {
ret = JSON.parse(body);
} catch (e) {
this._options.logger && this._options.logger('Alexa-Remote: Response: No/Invalid JSON');
callback && callback(new Error('no JSON'), body);
callback = null;
return;
}

this._options.logger && this._options.logger('Alexa-Remote: Response: ' + JSON.stringify(ret));
callback(null, ret);
callback = null;
return;
}

this._options.logger && this._options.logger('Alexa-Remote: Response: ' + JSON.stringify(ret));
callback (null, ret);
callback = null;
}
});
});
});
} catch(err) {
this._options.logger && this._options.logger('Alexa-Remote: Response: Exception: ' + err);
if (typeof callback === 'function'/* && callback.length >= 2*/) {
callback (err, null);
callback = null;
}
return;
}

req.on('error', (e) => {
this._options.logger && this._options.logger('Alexa-Remote: Response: Error: ' + e);
Expand Down
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"layla.amazon.de"
],
"dependencies": {
"alexa-cookie2": "^3.2.1",
"alexa-cookie2": "^3.3.0",
"https": "^1.0.0",
"querystring": "^0.2.0",
"ws": "^7.3.1",
"extend": "^3.0.2",
"uuid": "^8.1.0"
"uuid": "^8.2.0"
},
"devDependencies": {
"@alcalzone/release-script": "^1.6.0"
Expand Down

0 comments on commit 70732e0

Please sign in to comment.