From 1a5a416e0e1c733b0bdc3d4265620bd3b2f27a67 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Mon, 20 Nov 2017 13:09:36 +0100 Subject: [PATCH] Increase stellar.toml size limit, improve error message --- src/federation_server.js | 6 +++++- src/stellar_toml_resolver.js | 9 ++++++++- test/unit/federation_server_test.js | 2 +- test/unit/stellar_toml_resolver_test.js | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/federation_server.js b/src/federation_server.js index 1b13abeee..5a16f4dfe 100644 --- a/src/federation_server.js +++ b/src/federation_server.js @@ -170,7 +170,11 @@ export class FederationServer { }) .catch(response => { if (response instanceof Error) { - return Promise.reject(response); + if (response.message.match(/^maxContentLength size/)) { + throw new Error(`federation response exceeds allowed size of ${FEDERATION_RESPONSE_MAX_SIZE}`); + } else { + return Promise.reject(response); + } } else { return Promise.reject(new BadResponseError(`Server query failed. Server responded: ${response.status} ${response.statusText}`, response.data)); } diff --git a/src/stellar_toml_resolver.js b/src/stellar_toml_resolver.js index 1037f70e9..917ea6d27 100644 --- a/src/stellar_toml_resolver.js +++ b/src/stellar_toml_resolver.js @@ -4,7 +4,7 @@ import toml from 'toml'; import {Config} from "./config"; // STELLAR_TOML_MAX_SIZE is the maximum size of stellar.toml file -export const STELLAR_TOML_MAX_SIZE = 5 * 1024; +export const STELLAR_TOML_MAX_SIZE = 100 * 1024; /** * StellarTomlResolver allows resolving `stellar.toml` files. @@ -46,6 +46,13 @@ export class StellarTomlResolver { } catch (e) { return Promise.reject(new Error(`Parsing error on line ${e.line}, column ${e.column}: ${e.message}`)); } + }) + .catch(err => { + if (err.message.match(/^maxContentLength size/)) { + throw new Error(`stellar.toml file exceeds allowed size of ${STELLAR_TOML_MAX_SIZE}`); + } else { + throw err; + } }); } } diff --git a/test/unit/federation_server_test.js b/test/unit/federation_server_test.js index b36541ae2..f3d8f4583 100644 --- a/test/unit/federation_server_test.js +++ b/test/unit/federation_server_test.js @@ -222,7 +222,7 @@ FEDERATION_SERVER="https://api.stellar.org/federation" }).listen(4444, () => { new StellarSdk.FederationServer('http://localhost:4444/federation', 'stellar.org', {allowHttp: true}) .resolveAddress('bob*stellar.org') - .should.be.rejectedWith(/maxContentLength size of [0-9]+ exceeded/) + .should.be.rejectedWith(/federation response exceeds allowed size of [0-9]+/) .notify(done) .then(() => tempServer.close()); }); diff --git a/test/unit/stellar_toml_resolver_test.js b/test/unit/stellar_toml_resolver_test.js index fb44a6727..88e97048a 100644 --- a/test/unit/stellar_toml_resolver_test.js +++ b/test/unit/stellar_toml_resolver_test.js @@ -101,7 +101,7 @@ FEDERATION_SERVER="https://api.stellar.org/federation" res.end(response); }).listen(4444, () => { StellarSdk.StellarTomlResolver.resolve("localhost:4444", {allowHttp: true}) - .should.be.rejectedWith(/maxContentLength size of [0-9]+ exceeded/) + .should.be.rejectedWith(/stellar.toml file exceeds allowed size of [0-9]+/) .notify(done) .then(() => tempServer.close()); });