Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a way to add maxHeaderSize to HTTPS server #3401

Closed
SantanM opened this issue Jun 4, 2021 · 3 comments
Closed

is there a way to add maxHeaderSize to HTTPS server #3401

SantanM opened this issue Jun 4, 2021 · 3 comments

Comments

@SantanM
Copy link

SantanM commented Jun 4, 2021

Hi Team,

  • Node.js Version: 12.19.0
  • OS: Mac OS
  • Scope (install, code, runtime, meta, other?): Runtime
  • Module (and version) (if relevant): HTTPS

I would like to know if it is possible to set maxHeaderSize option to the HTTPS server. Out of the box HTTPS module does not have this option, and I am wondering if there is way to do so. The problem I have is, the server throws 431 error response due to the large header size in the incoming request to the HTTPS server.

Is there a solution to my problem? It must be a common problem, but I could not find anyone reporting it anywhere. It seems (according to the documentation) the options of HTTP server are applicable to HTTPS, but the value does not seem to work in my case (seeing 431 error always). How can I verify the maxHeaderSize value using HTTPS server. My code looks like -

const server = https.createServer({
  key: process.env.SSL_PRIVATE_KEY,
  cert: process.env.SSL_PUBLIC_CERT,
  maxHeaderSize: 8192*6
}, app).listen(PORT, () => {
  log.info(`🚀 Approuter started on port ${PORT}`);
console.log(server.maxHeaderSize); // outputs undefined
});
@gireeshpunathil
Copy link
Member

@nodejs/http

@mcollina
Copy link
Member

This should be possible as the whole machinery is the same. It probably needs some additional documentation fix.

@ShogunPanda
Copy link

Hi @gireeshpunathil.

I've tried across different Node version. The problem exists only for Node 12, while it is fixed on 14 and 16. If you look at the documentation and its history, you will notice that maxHeaderSize has been added in 13.3.0, so it's not supported on your Node version.
Given that 12 is now not supported anymore, if you update to Node 16 (the Active LTS) or at least 14 (the Maintenance LTS), the problem should go away by itself.

For anybody else interested in reproducing the issue, you can use code below:

import { readFileSync } from 'fs'
import { createServer } from 'https'
import undici from 'undici'

const server = createServer(
  {
    key: readFileSync('ssl/privkey.pem'),
    cert: readFileSync('ssl/fullchain.pem'),
    maxHeaderSize: 8192 * 6
  },
  (req, res) => {
    res.writeHead(200)
    res.end(`X-Payload header size: ${req.headers['x-payload'].length}`)
  }
).listen(0, async () => {
  const port = server.address().port
  console.log(`Server is listening on port ${port} using Node ${process.version} ...`)

  const payload = Buffer.alloc(8192 * 5, '123').toString('utf-8')

  const {
    statusCode,
    headers,
    body: data
  } = await undici.request(`https://home.cowtech.it:${port}`, {
    headers: { 'x-payload': payload },
    dispatcher: new undici.Agent({ pipelining: 0 })
  })

  let body = Buffer.alloc(0)
  for await (const chunk of data) {
    body = Buffer.concat([body, chunk])
  }

  console.log('Received reply:\n\n' + JSON.stringify({ statusCode, headers, body: body.toString('utf-8') }, null, 2))
  server.close()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants