Skip to content

Commit 9e6abbe

Browse files
Configurable JSON parser limit (#51)
* Configurable JSON parser limit Signed-off-by: Gabriel Indik <[email protected]> * Limit in config file Signed-off-by: Gabriel Indik <[email protected]>
1 parent 6fb2dfd commit 9e6abbe

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const start = async () => {
133133
});
134134

135135
apiApp.use(express.urlencoded({ extended: true }));
136-
apiApp.use(express.json());
136+
apiApp.use(express.json({limit: config.jsonParserLimit ?? utils.constants.DEFAULT_JSON_PARSER_LIMIT}));
137137
apiApp.use('/api/v1', apiRouter);
138138
apiApp.use(errorHandler);
139139

src/lib/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IConfig {
2929
id: string
3030
endpoint: string
3131
}[]
32+
jsonParserLimit?: string
3233
}
3334

3435
export interface IFile {

src/lib/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const constants = {
4444
MAX_EVENT_QUEUE_SIZE: 1000,
4545
HASH_HEADER_NAME: 'dx-hash',
4646
SIZE_HEADER_NAME: 'dx-size',
47-
LAST_UPDATE_HEADER_NAME: 'dx-last-update'
47+
LAST_UPDATE_HEADER_NAME: 'dx-last-update',
48+
DEFAULT_JSON_PARSER_LIMIT: '1mb'
4849
};
4950
const log = new Logger('utils.ts');
5051
axios.defaults.timeout = constants.REST_API_CALL_REQUEST_TIMEOUT;

src/schemas/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
}
6161
}
6262
}
63+
},
64+
"jsonParserLimit": {
65+
"type": "string",
66+
"pattern": "^\\d+(k|K|m|M|g|G|t|T|p|P)?(b|B)$"
6367
}
6468
}
6569
}

0 commit comments

Comments
 (0)