Skip to content

server.js: TRUST_PROXY hop-count uses lenient parseInt — 'TRUST_PROXY=1abc' silently sets hops=1 #223

@CryptoJones

Description

@CryptoJones

Problem

server.js parses the hop-count branch of TRUST_PROXY like this:

} else if (trustProxy && !isNaN(parseInt(trustProxy, 10))) {
    app.set('trust proxy', parseInt(trustProxy, 10));
}

parseInt is lenient — parseInt('1abc', 10) returns 1. An operator setting TRUST_PROXY=1abc (typo, leftover comma, autocomplete glitch) gets trust proxy partially honored at 1 hop instead of falling through to the no-trust default. There's no warning anywhere.

Fix

Use a strict regex match (/^\d+$/) before the parseInt. Invalid values fall through to the implicit default. Operator typos surface as observable "X-Forwarded-For not trusted" symptoms rather than partial-trust silence.

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions