diff --git a/api/src/config.js b/api/src/config.js index 034e3b6a5..e23e4f3c6 100644 --- a/api/src/config.js +++ b/api/src/config.js @@ -24,6 +24,13 @@ const options = { x => fss.exists_sync(x) || `Directory ${x} does not exist`, ], }, + body_parser_json: { + desc: 'Body size limit for JSON requests', + default: '100kb', //https://github.com/expressjs/body-parser#limit-2 + validators: [ + x => /^\d+(kb|mb|gb)$/i.test(x) || `${x} is not a valid size (e.g. 10mb, 100kb)`, + ], + }, runner_uid_min: { desc: 'Minimum uid to use for runner', default: 1001, diff --git a/api/src/index.js b/api/src/index.js index 4a6dd422d..601eb41d4 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -65,7 +65,7 @@ expressWs(app); logger.debug('Registering middleware'); app.use(body_parser.urlencoded({ extended: true })); - app.use(body_parser.json()); + app.use(body_parser.json({ limit: config.body_parser_json })); app.use((err, req, res, next) => { return res.status(400).send({ diff --git a/docs/configuration.md b/docs/configuration.md index 163cd08ff..982bc6919 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -30,6 +30,17 @@ Port and IP address to bind the Piston API to. This changes the bind address inside the container, and thus serves no purpose when running in a container +## Body Parser JSON Limit + +```yaml +key: PISTON_BODY_PARSER_JSON +default: 100kb +``` + +Maximum size of the JSON request body. + +Increase this value if you need to submit large code or arguments (e.g. `10mb`). + ## Data Directory ```yaml