Skip to content

[ORCA-77] Increase max header size - #8

Closed
clintonium-119 wants to merge 4 commits into
release-v1.0.4from
ORCA-77-increase-max-header-size
Closed

[ORCA-77] Increase max header size#8
clintonium-119 wants to merge 4 commits into
release-v1.0.4from
ORCA-77-increase-max-header-size

Conversation

@clintonium-119

@clintonium-119 clintonium-119 commented Jul 28, 2026

Copy link
Copy Markdown
Member

ORCA-77

Node's 16 KB default rejects oversized request headers with a bodyless 431 before the request reaches any route, so it cannot be handled or logged in app code.

This attempts to mitigate the issue by bumping up to 32kb, providing hopefully enough headroom for the application cookies (which have been optimized by pruning stale entries in ORCA-76, plus any extra overhead added by browser extensions that can impact the header size as well.

Node's 16 KB default rejects oversized request headers with a
bodyless 431 before the request reaches any route, so it cannot be
handled or logged in app code. Users running many browser
extensions have exceeded it, making the tool unusable for them in
every environment while working normally in incognito.

Build the server explicitly rather than via app.listen so dev and
production share one limit, and expose MAX_HTTP_HEADER_SIZE to
adjust without a rebuild.

Verified: a 20 KB request header returns 431 on the default and
200 with this change.
@clintonium-119
clintonium-119 requested a review from krystophv July 28, 2026 18:40
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved HTTP server handling for requests with larger headers.
    • Added support for configuring the maximum allowed HTTP header size through an environment setting, with a safe default applied when no value is provided.
    • Preserved the existing server startup behavior and connection logging.

Walkthrough

server.mjs now starts the application through Node’s createServer, configuring maxHeaderSize from MAX_HTTP_HEADER_SIZE with a default of 32768, while preserving the existing port and startup logging behavior.

Changes

HTTP server startup

Layer / File(s) Summary
Configurable HTTP server creation
server.mjs
The server imports Node’s createServer, reads MAX_HTTP_HEADER_SIZE with a 32768 default, and starts the application through the configured HTTP server.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: krystophv, copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: increasing the HTTP header size limit.
Description check ✅ Passed The description is directly related to the change and explains why the header limit is being raised.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ORCA-77-increase-max-header-size

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@clintonium-119
clintonium-119 changed the base branch from main to release-v1.0.4 July 28, 2026 18:53
@krystophv
krystophv requested a review from Copilot July 29, 2026 16:08
@krystophv

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR increases the Node/HTTP server maximum request header size to reduce occurrences of bodyless 431 responses caused by oversized cookie/header payloads, allowing requests to reach Express/React Router where they can be handled and logged.

Changes:

  • Swap app.listen(...) for an explicit node:http server with maxHeaderSize.
  • Add MAX_HTTP_HEADER_SIZE env override with a default of 32768 bytes (32KB).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server.mjs
process.env.NODE_ENV === 'production' ? 'http://0.0.0.0' : 'http://localhost';

app.listen(port, () => console.log(host + ':' + port));
const maxHeaderSize = Number(process.env.MAX_HTTP_HEADER_SIZE) || 32768;

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server.mjs`:
- Line 49: Configure the ESLint environment for Node.js in the repository’s
ESLint configuration so the global process used by server.mjs is recognized.
Update the relevant ESLint settings without suppressing the undefined-variable
rule or changing maxHeaderSize.
- Line 49: Update the maxHeaderSize configuration to validate
MAX_HTTP_HEADER_SIZE before passing it to createServer: accept only finite,
valid integer values within Node’s supported range, and fall back to 32768 or
explicitly reject invalid input. Ensure values such as -1, 32768.5, and Infinity
cannot reach createServer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 94f80703-97e7-44cb-a669-10790211e5c8

📥 Commits

Reviewing files that changed from the base of the PR and between 8bd5b58 and 85113ba.

📒 Files selected for processing (1)
  • server.mjs

Comment thread server.mjs
process.env.NODE_ENV === 'production' ? 'http://0.0.0.0' : 'http://localhost';

app.listen(port, () => console.log(host + ':' + port));
const maxHeaderSize = Number(process.env.MAX_HTTP_HEADER_SIZE) || 32768;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Resolve the ESLint process error.

The provided ESLint analysis reports process as undefined on this new line, so the repository lint command will fail. Configure Node globals for server.mjs in the ESLint configuration rather than suppressing the rule.

🧰 Tools
🪛 ESLint

[error] 49-49: 'process' is not defined.

(no-undef)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.mjs` at line 49, Configure the ESLint environment for Node.js in the
repository’s ESLint configuration so the global process used by server.mjs is
recognized. Update the relevant ESLint settings without suppressing the
undefined-variable rule or changing maxHeaderSize.

Source: Linters/SAST tools


🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

node --input-type=module <<'NODE'
import { createServer } from 'node:http';

for (const maxHeaderSize of [-1, 32768.5, 32768]) {
  try {
    createServer({ maxHeaderSize });
    console.log(maxHeaderSize, 'accepted');
  } catch (error) {
    console.log(maxHeaderSize, error.code ?? error.name);
  }
}
NODE

Repository: tidepool-org/orca-remix

Length of output: 384


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect server.mjs around the reported line.
if [ -f server.mjs ]; then
  sed -n '1,90p' server.mjs | nl -ba
else
  echo "server.mjs not found"
fi

# Probe Node's maxHeaderSize behavior for the exact env-related values and edge cases.
printf '\n--- Node createServer createServerOptions.maxHeaderSize behavior ---\n'
node --input-type=module <<'NODE'
import { createServer } from 'node:http';

const cases = [
  '-1',
  '32768.5',
  '0',
  '1',
  '32768',
  'not-a-number',
  '',
  'Infinity',
  '-Infinity',
  '1.0',
  '1.1',
];

for (const raw of cases) {
  const configured = Number(raw);
  const maxHeaderSize = configured || 32768;
  try {
    const server = createServer({ maxHeaderSize });
    server.close(() => console.log(`'${raw}' -> configured=${configured}, fallback=${maxHeaderSize}, accepted`));
  } catch (error) {
    console.log(`'${raw}' -> configured=${configured}, fallback=${maxHeaderSize}, rejected ${error.code ?? error.name}: ${error.message}`);
  }
}
NODE

Repository: tidepool-org/orca-remix

Length of output: 201


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "PWD=$(pwd)"
echo "server.mjs exists=$(if [ -f server.mjs ]; then echo yes; else echo no; fi)"

# Locate and inspect server.mjs around the reported line.
if [ -f server.mjs ]; then
  sed -n '1,100p' server.mjs
fi

echo
echo "--- Node createServer createServerOptions.maxHeaderSize behavior ---"
node --input-type=module <<'NODE'
import { createServer } from 'node:http';

const cases = [
  '-1',
  '32768.5',
  '0',
  '1',
  '32768',
  'not-a-number',
  '',
  'Infinity',
  '-Infinity',
  '1.0',
  '1.1',
];

for (const raw of cases) {
  const configured = Number(raw);
  const maxHeaderSize = configured || 32768;
  try {
    const server = createServer({ maxHeaderSize });
    server.close(() => console.log(`'${raw}' -> configured=${configured}, fallback=${maxHeaderSize}, accepted`));
  } catch (error) {
    console.log(`'${raw}' -> configured=${configured}, fallback=${maxHeaderSize}, rejected ${error.code ?? error.name}: ${error.message}`);
  }
}
NODE

Repository: tidepool-org/orca-remix

Length of output: 2793


Validate MAX_HTTP_HEADER_SIZE before passing it to Node.

Number(...) || 32768 lets invalid truthy values like -1, 32768.5, or Infinity reach createServer({ maxHeaderSize }), where Node rejects them as out-of-range and prevents the server from starting. Reject invalid values explicitly or fall back to the default.

🧰 Tools
🪛 ESLint

[error] 49-49: 'process' is not defined.

(no-undef)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server.mjs` at line 49, Update the maxHeaderSize configuration to validate
MAX_HTTP_HEADER_SIZE before passing it to createServer: accept only finite,
valid integer values within Node’s supported range, and fall back to 32768 or
explicitly reject invalid input. Ensure values such as -1, 32768.5, and Infinity
cannot reach createServer.

@clintonium-119

Copy link
Copy Markdown
Member Author

I'm going to close this PR - the actual fix for the 431 lied elsewhere.

@clintonium-119
clintonium-119 deleted the ORCA-77-increase-max-header-size branch July 31, 2026 16:32
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

Successfully merging this pull request may close these issues.

3 participants