Merge pull request #33361 from overleaf/copilot/remove-direct-use-of-body-parser

Remove direct use of body-parser in favour of express built-ins

GitOrigin-RevId: 656c5f216daf68e86d53ae07d272e080bd5ab27f
This commit is contained in:
Lucie Germain
2026-09-17 11:14:46 +00:00
committed by Copybot
parent 6be5db7667
commit 210ced0d31
25 changed files with 24 additions and 65 deletions
-1
View File
@@ -15,7 +15,6 @@
"license": "AGPL-3.0-only",
"devDependencies": {
"@types/node-fetch": "^2.6.13",
"body-parser": "1.20.4",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"express": "4.22.1",
@@ -1,5 +1,4 @@
const express = require('express')
const bodyParser = require('body-parser')
const { EventEmitter } = require('node:events')
const http = require('node:http')
const https = require('node:https')
@@ -10,7 +9,7 @@ class TestServer {
this.app = express()
this.events = new EventEmitter()
this.app.use(bodyParser.json())
this.app.use(express.json())
this.app.use((req, res, next) => {
this.events.emit('request-received')
this.lastReq = req
+1 -1
View File
@@ -68,7 +68,7 @@
"react-dom": "18.3.1",
"i18next-scanner/i18next": "23.16.8",
"downshift": "9.0.9",
"body-parser@npm:1.20.4": "patch:body-parser@npm%3A1.20.4#~/.yarn/patches/body-parser-npm-1.20.4.patch",
"body-parser": "patch:body-parser@npm%3A1.20.4#~/.yarn/patches/body-parser-npm-1.20.4.patch",
"cypress-multi-reporters": "patch:cypress-multi-reporters@npm%3A2.0.5#~/.yarn/patches/cypress-multi-reporters-npm-2.0.5.patch",
"forwarded@npm:0.2.0": "patch:forwarded@npm%3A0.2.0#~/.yarn/patches/forwarded-npm-0.2.0.patch",
"multer@npm:2.1.1": "patch:multer@npm%3A2.1.1#~/.yarn/patches/multer-npm-2.1.1.patch",
-1
View File
@@ -22,7 +22,6 @@
"@overleaf/promise-utils": "*",
"@overleaf/settings": "*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"exegesis-express": "4.0.0",
"express": "4.22.1",
"mongodb": "6.12.0"
+5 -6
View File
@@ -15,7 +15,6 @@ import ProjectPersistenceManager from './app/js/ProjectPersistenceManager.js'
import OutputCacheManager from './app/js/OutputCacheManager.js'
import express from 'express'
import bodyParser from 'body-parser'
import net from 'node:net'
import os from 'node:os'
@@ -73,7 +72,7 @@ app.param('build_id', function (req, res, next, buildId) {
app.post(
'/project/:project_id/compile',
bodyParser.json({ limit: Settings.compileSizeLimit }),
express.json({ limit: Settings.compileSizeLimit }),
CompileController.compile
)
app.post('/project/:project_id/compile/stop', CompileController.stopCompile)
@@ -88,7 +87,7 @@ app.post('/project/:project_id/status', CompileController.status)
// Per-user containers
app.post(
'/project/:project_id/user/:user_id/compile',
bodyParser.json({ limit: Settings.compileSizeLimit }),
express.json({ limit: Settings.compileSizeLimit }),
CompileController.compile
)
app.post(
@@ -113,14 +112,14 @@ app.get(
// This needs to be before GET /project/:project_id/build/:build_id/output/*
app.get(
'/project/:project_id/build/:build_id/output/output.zip',
bodyParser.json(),
express.json(),
OutputController.createOutputZip
)
// This needs to be before GET /project/:project_id/user/:user_id/build/:build_id/output/*
app.get(
'/project/:project_id/user/:user_id/build/:build_id/output/output.zip',
bodyParser.json(),
express.json(),
OutputController.createOutputZip
)
@@ -142,7 +141,7 @@ app.post(
)
app.post(
'/project/:project_id/user/:user_id/download/project-to-document',
bodyParser.json({ limit: Settings.compileSizeLimit }),
express.json({ limit: Settings.compileSizeLimit }),
ConversionController.convertProjectToDocument
)
app.post(
-1
View File
@@ -26,7 +26,6 @@
"@overleaf/validation-tools": "workspace:*",
"archiver": "5.3.2",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"dockerode": "^4.0.9",
"express": "4.22.1",
+2 -3
View File
@@ -6,7 +6,6 @@ import Metrics from '@overleaf/metrics'
import Settings from '@overleaf/settings'
import logger from '@overleaf/logger'
import express from 'express'
import bodyParser from 'body-parser'
import { handleValidationError } from '@overleaf/validation-tools'
import mongodb from './app/js/mongodb.js'
import Errors from './app/js/Errors.js'
@@ -69,12 +68,12 @@ app.get('/project/:project_id/doc/:doc_id/peek', HttpController.peekDoc)
// Add 64kb overhead for the JSON encoding, and double the size to allow for ranges in the json payload
app.post(
'/project/:project_id/doc/:doc_id',
bodyParser.json({ limit: Settings.maxJsonRequestSize }),
express.json({ limit: Settings.maxJsonRequestSize }),
HttpController.updateDoc
)
app.patch(
'/project/:project_id/doc/:doc_id',
bodyParser.json(),
express.json(),
HttpController.patchDoc
)
app.delete('/project/:project_id/doc/:doc_id', (req, res) => {
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/stream-utils": "^0.1.0",
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"express": "4.22.1",
"lodash": "^4.18.1",
+1 -3
View File
@@ -17,13 +17,11 @@ const HttpController = require('./app/js/HttpController')
const mongodb = require('./app/js/mongodb')
const async = require('async')
const bodyParser = require('body-parser')
Metrics.event_loop.monitor(logger, 100)
Metrics.open_sockets.monitor()
const app = express()
app.use(bodyParser.json({ limit: Settings.maxJsonRequestSize }))
app.use(express.json({ limit: Settings.maxJsonRequestSize }))
Metrics.injectMetricsRoute(app)
DispatchManager.createAndStartDispatchers(Settings.dispatcherCount)
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/settings": "workspace:*",
"@types/chai-as-promised": "^7.1.8",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bull": "^3.18.0",
"bunyan": "^1.8.15",
"diff-match-patch": "overleaf/diff-match-patch#89805f9c671a77a263fc53461acd62aa7498f688",
@@ -1,5 +1,4 @@
const express = require('express')
const bodyParser = require('body-parser')
const { expressify } = require('@overleaf/promise-utils')
const app = express()
const MAX_REQUEST_SIZE = 2 * (2 * 1024 * 1024 + 64 * 1024)
@@ -79,7 +78,7 @@ const MockDocstoreApi = {
app.patch(
'/project/:project_id/doc/:doc_id',
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
express.json({ limit: MAX_REQUEST_SIZE }),
expressify(async (req, res) => {
try {
await MockDocstoreApi.patchDocument(
@@ -2,7 +2,6 @@ let MockWebApi
const basicAuth = require('basic-auth')
const tsscmp = require('tsscmp')
const express = require('express')
const bodyParser = require('body-parser')
const { expressify } = require('@overleaf/promise-utils')
const Settings = require('@overleaf/settings')
const app = express()
@@ -113,7 +112,7 @@ module.exports = MockWebApi = {
app.post(
'/project/:project_id/doc/:doc_id',
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
express.json({ limit: MAX_REQUEST_SIZE }),
expressify(async (req, res, next) => {
await this.setDocumentController(req, res, next)
})
-1
View File
@@ -25,7 +25,6 @@
"@overleaf/object-persistor": "workspace:*",
"@overleaf/settings": "workspace:*",
"@overleaf/stream-utils": "^0.1.0",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"express": "4.22.1",
"glob": "^12.0.0",
+2 -3
View File
@@ -12,7 +12,6 @@ const helmet = require('helmet')
const HTTPStatus = require('http-status')
const logger = require('@overleaf/logger')
const Metrics = require('@overleaf/metrics')
const bodyParser = require('body-parser')
const security = require('./api/middleware/security')
const healthChecks = require('./api/controllers/health_checks')
const { mongodb, loadGlobalBlobs } = require('./storage')
@@ -37,9 +36,9 @@ Metrics.leaked_sockets.monitor(logger)
// We may have fairly large JSON bodies when receiving large Changes. Clients
// may have to handle 413 status codes and try creating files instead of sending
// text content in changes.
app.use(bodyParser.json({ limit: '12MB' }))
app.use(express.json({ limit: '12MB' }))
app.use(
bodyParser.urlencoded({
express.urlencoded({
extended: false,
})
)
-1
View File
@@ -21,7 +21,6 @@
"archiver": "^5.3.0",
"basic-auth": "^2.0.1",
"bluebird": "^3.7.2",
"body-parser": "1.20.4",
"bull": "^4.16.5",
"bunyan": "^1.8.12",
"check-types": "^11.1.2",
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/settings": "workspace:*",
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"express": "4.22.1",
"mongodb-legacy": "6.1.3",
+2 -3
View File
@@ -2,7 +2,6 @@ import Metrics from '@overleaf/metrics'
import logger from '@overleaf/logger'
import OError from '@overleaf/o-error'
import express from 'express'
import bodyParser from 'body-parser'
import * as Errors from './Errors.js'
import * as Router from './Router.js'
import { handleValidationError } from '@overleaf/validation-tools'
@@ -40,8 +39,8 @@ HistoryLogger.addSerializers({
})
export const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(Metrics.http.monitor(logger))
Router.initialize(app)
Metrics.injectMetricsRoute(app)
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/stream-utils": "workspace:*",
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"diff-match-patch": "overleaf/diff-match-patch#89805f9c671a77a263fc53461acd62aa7498f688",
"express": "4.22.1",
+2 -2
View File
@@ -1,11 +1,11 @@
import metrics from '@overleaf/metrics'
import logger from '@overleaf/logger'
import settings from '@overleaf/settings'
import express from 'express'
import WebsocketController from './WebsocketController.js'
import HttpController from './HttpController.js'
import HttpApiController from './HttpApiController.js'
import WebsocketAddressManager from './WebsocketAddressManager.js'
import bodyParser from 'body-parser'
import base64id from 'base64id'
import Errors from './Errors.js'
import { z, zz } from '@overleaf/validation-tools'
@@ -157,7 +157,7 @@ export default Router = {
app.post(
'/project/:project_id/message/:message',
bodyParser.json({ limit: '5mb' }),
express.json({ limit: '5mb' }),
HttpApiController.sendMessage
)
app.get(
-1
View File
@@ -26,7 +26,6 @@
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"base64id": "0.1.0",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"connect-redis": "^6.1.3",
"cookie-parser": "^1.4.6",
@@ -11,7 +11,6 @@
*/
import sinon from 'sinon'
import express from 'express'
import bodyParser from 'body-parser'
let MockWebServer
@@ -90,7 +89,7 @@ export default MockWebServer = {
return callback()
}
const app = express()
app.use(bodyParser.json())
app.use(express.json())
app.post('/project/:project_id/join', MockWebServer.joinProjectRequest)
return app
.listen(3000, error => {
@@ -1,4 +1,4 @@
import bodyParser from 'body-parser'
import express from 'express'
import HttpErrorHandler from '../Features/Errors/HttpErrorHandler.mjs'
function isBodyParserError(nextArg) {
@@ -13,7 +13,7 @@ function isBodyParserError(nextArg) {
}
const wrapBodyParser = method => opts => {
const middleware = bodyParser[method](opts)
const middleware = express[method](opts)
return function bodyParser(req, res, next) {
middleware(req, res, nextArg => {
if (isBodyParserError(nextArg)) {
-1
View File
@@ -114,7 +114,6 @@
"base-x": "^4.0.1",
"basic-auth": "^2.0.1",
"bcrypt": "^6.0.0",
"body-parser": "1.20.4",
"bowser": "^2.11.0",
"bull": "^3.18.0",
"bunyan": "^1.8.15",
@@ -1,6 +1,5 @@
import OError from '@overleaf/o-error'
import express from 'express'
import bodyParser from 'body-parser'
/**
* Abstract class for running a mock API via Express. Handles setting up of
@@ -49,8 +48,8 @@ class AbstractMockApi {
this.debug = debug
this.port = port
this.app = express()
this.app.use(bodyParser.json())
this.app.use(bodyParser.urlencoded({ extended: true }))
this.app.use(express.json())
this.app.use(express.urlencoded({ extended: true }))
}
/**
+1 -20
View File
@@ -6576,7 +6576,6 @@ __metadata:
"@pollyjs/core": "npm:^6.0.6"
"@pollyjs/persister-fs": "npm:^6.0.6"
bluebird: "npm:^3.7.2"
body-parser: "npm:1.20.4"
bull: "npm:^3.18.0"
camelcase-keys: "npm:^4.2.0"
chai: "npm:^4.3.6"
@@ -6621,7 +6620,6 @@ __metadata:
acorn: "npm:^7.1.1"
ajv: "npm:^6.12.0"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
exegesis-express: "npm:4.0.0"
@@ -6650,7 +6648,6 @@ __metadata:
"@overleaf/settings": "workspace:*"
"@overleaf/stream-utils": "workspace:*"
"@overleaf/validation-tools": "workspace:*"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -6717,7 +6714,6 @@ __metadata:
"@overleaf/validation-tools": "workspace:*"
archiver: "npm:5.3.2"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -6781,7 +6777,6 @@ __metadata:
"@overleaf/stream-utils": "npm:^0.1.0"
"@overleaf/validation-tools": "workspace:*"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -6816,7 +6811,6 @@ __metadata:
"@types/chai-as-promised": "npm:^7.1.8"
async: "npm:^3.2.5"
basic-auth: "npm:^2.0.1"
body-parser: "npm:1.20.4"
bull: "npm:^3.18.0"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
@@ -6858,7 +6852,6 @@ __metadata:
dependencies:
"@overleaf/o-error": "workspace:*"
"@types/node-fetch": "npm:^2.6.13"
body-parser: "npm:1.20.4"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
express: "npm:4.22.1"
@@ -6884,7 +6877,6 @@ __metadata:
"@overleaf/object-persistor": "workspace:*"
"@overleaf/settings": "workspace:*"
"@overleaf/stream-utils": "npm:^0.1.0"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -6922,7 +6914,6 @@ __metadata:
"@overleaf/settings": "workspace:*"
"@overleaf/stream-utils": "workspace:*"
base64-stream: "npm:^0.1.2"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7053,7 +7044,6 @@ __metadata:
"@overleaf/settings": "workspace:*"
"@overleaf/validation-tools": "workspace:*"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7140,7 +7130,6 @@ __metadata:
"@overleaf/stream-utils": "workspace:*"
"@overleaf/validation-tools": "workspace:*"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7203,7 +7192,6 @@ __metadata:
"@overleaf/validation-tools": "workspace:*"
async: "npm:^3.2.5"
base64id: "npm:0.1.0"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7284,7 +7272,6 @@ __metadata:
"@types/adm-zip": "npm:^0.5.7"
"@types/uuid": "npm:^9.0.8"
adm-zip: "npm:^0.5.12"
body-parser: "npm:1.20.4"
cypress: "npm:15.12.0"
cypress-multi-reporters: "npm:^2.0.5"
express: "npm:4.22.1"
@@ -7333,7 +7320,6 @@ __metadata:
"@overleaf/settings": "workspace:*"
args-js: "npm:0.10.12"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7366,7 +7352,6 @@ __metadata:
"@overleaf/promise-utils": "workspace:*"
"@overleaf/settings": "workspace:*"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7408,7 +7393,6 @@ __metadata:
"@overleaf/settings": "workspace:*"
"@types/simple-oauth2": "npm:^5.0.7"
async: "npm:^3.2.5"
body-parser: "npm:1.20.4"
bunyan: "npm:^1.8.15"
chai: "npm:^4.3.6"
chai-as-promised: "npm:^7.1.1"
@@ -7589,7 +7573,6 @@ __metadata:
base-x: "npm:^4.0.1"
basic-auth: "npm:^2.0.1"
bcrypt: "npm:^6.0.0"
body-parser: "npm:1.20.4"
bootstrap: "npm:^5.3.7"
bowser: "npm:^2.11.0"
bull: "npm:^3.18.0"
@@ -14271,7 +14254,7 @@ __metadata:
languageName: node
linkType: hard
"body-parser@npm:1.20.4, body-parser@npm:^1.18.3, body-parser@npm:^1.19.0, body-parser@npm:^1.20.3, body-parser@npm:~1.20.3":
"body-parser@npm:1.20.4":
version: 1.20.4
resolution: "body-parser@npm:1.20.4"
dependencies:
@@ -22972,7 +22955,6 @@ __metadata:
babel-loader: "npm:^10.1.1"
babel-plugin-react-transform: "npm:^3.0.0"
babel-plugin-transform-react-remove-prop-types: "npm:^0.4.24"
body-parser: "npm:^1.20.3"
bootstrap: "npm:5.3.3"
combobo: "npm:^2.0.4"
compression: "npm:^1.7.1"
@@ -26241,7 +26223,6 @@ __metadata:
basic-auth: "npm:^2.0.1"
benny: "npm:^3.7.1"
bluebird: "npm:^3.7.2"
body-parser: "npm:1.20.4"
bull: "npm:^4.16.5"
bunyan: "npm:^1.8.12"
chai: "npm:^4.3.6"