Skip to content

Commit 8870949

Browse files
authored
Revert "feat: add env var for additional trusted proxy IPs/subnets"
1 parent a0b145d commit 8870949

3 files changed

Lines changed: 2 additions & 33 deletions

File tree

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This image is executed as non root by default and is fully compliant with Kubern
1919
- [Basic Usage](#basic-usage)
2020
- [Choose your ports](#choose-your-ports)
2121
- [Use your own certificates](#use-your-own-certificates)
22-
- [Trust additional proxy IPs](#trust-additional-proxy-ips)
2322
- [Decode JWT header](#decode-jwt-header)
2423
- [Disable ExpressJS log lines](#disable-expressjs-log-lines)
2524
- [Do not log specific path](#do-not-log-specific-path)
@@ -97,13 +96,6 @@ You can use volume mounting to substitute the certificate and private key with y
9796
You can use the environment variables `HTTPS_CERT_FILE` and `HTTPS_KEY_FILE` to define the location of existing certificate and private key inside container.
9897

9998

100-
## Trust additional proxy IPs
101-
102-
By default, Express is configured to trust forwarded proxy headers from loopback, link-local, and private IP ranges. To also trust additional proxy IPs or subnets, set `ADDITIONAL_TRUSTED_PROXIES` to a single value or a comma-separated list.
103-
104-
docker run -e ADDITIONAL_TRUSTED_PROXIES="2001:db8::/32,203.0.113.10" -p 8080:8080 -p 8443:8443 --rm -t mendhak/http-https-echo:40
105-
106-
10799
## Decode JWT header
108100

109101
If you specify the header that contains the JWT, the echo output will contain the decoded JWT. Use the `JWT_HEADER` environment variable for this.

index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@ const {
1717
PROMETHEUS_WITH_METHOD = 'true',
1818
PROMETHEUS_WITH_STATUS = 'true',
1919
PROMETHEUS_METRIC_TYPE = 'summary',
20-
MAX_HEADER_SIZE = 1048576,
21-
ADDITIONAL_TRUSTED_PROXIES
20+
MAX_HEADER_SIZE = 1048576
2221
} = process.env
2322

2423
const maxHeaderSize = parseInt(MAX_HEADER_SIZE, 10) || 1048576;
2524

26-
const trustProxy = [
27-
'loopback',
28-
'linklocal',
29-
'uniquelocal',
30-
...(ADDITIONAL_TRUSTED_PROXIES || '').split(',').map(proxy => proxy.trim()).filter(Boolean)
31-
];
3225

3326
const sleep = promisify(setTimeout);
3427
const metricsMiddleware = promBundle({
@@ -41,7 +34,7 @@ const metricsMiddleware = promBundle({
4134

4235
const app = express()
4336
app.set('json spaces', 2);
44-
app.set('trust proxy', trustProxy);
37+
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
4538

4639
if(PROMETHEUS_ENABLED === 'true') {
4740
app.use(metricsMiddleware);

tests.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,6 @@ fi
237237
message " Stop containers "
238238
stop_and_remove
239239

240-
message " Start container with additional trusted proxies "
241-
docker run -d --rm -e ADDITIONAL_TRUSTED_PROXIES="2001:db8::/32,198.51.100.0/24" --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
242-
wait_for_ready
243-
244-
REQUEST=$(curl -s -H "X-Forwarded-For: 203.0.113.10, 198.51.100.1, 2001:db8::1" http://localhost:8080/)
245-
if [[ "$(echo "$REQUEST" | jq -r '.ip')" == '203.0.113.10' ]]; then
246-
passed "Additional trusted proxies passed."
247-
else
248-
failed "Additional trusted proxies failed."
249-
echo "$REQUEST" | jq
250-
exit 1
251-
fi
252-
253-
message " Stop containers "
254-
stop_and_remove
255-
256240
message " Start container with different internal ports "
257241
docker run -d --rm -e HTTP_PORT=8888 -e HTTPS_PORT=9999 --name http-echo-tests -p 8080:8888 -p 8443:9999 -t mendhak/http-https-echo:testing
258242
wait_for_ready

0 commit comments

Comments
 (0)