Skip to content

Commit 0ac3cab

Browse files
committed
fix: warn once, handle array header, add default trusted proxies, sort CONFIGURATION.md A-Z
1 parent 5545654 commit 0ac3cab

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

CONFIGURATION.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@ The settings below are listed in alphabetical order by name. Please keep this ta
9999
| limits.event.content[].kinds | List of event kinds to apply limit. Use `[min, max]` for ranges. Optional. |
100100
| limits.event.content[].maxLength | Maximum length of `content`. Defaults to 1 MB. Disabled when set to zero. |
101101
| limits.event.createdAt.maxPositiveDelta | Maximum number of seconds an event's `created_at` can be in the future. Defaults to 900 (15 minutes). Disabled when set to zero. |
102-
| limits.event.createdAt.minNegativeDelta | Maximum number of secodns an event's `created_at` can be in the past. Defaults to zero. Disabled when set to zero. |
103-
| limits.event.eventId.minLeadingZeroBits | Leading zero bits required on every incoming event for proof of work. |
104-
| | Defaults to zero. Disabled when set to zero. |
102+
| limits.event.createdAt.minNegativeDelta | Maximum number of seconds an event's `created_at` can be in the past. Defaults to zero. Disabled when set to zero. |
103+
| limits.event.eventId.minLeadingZeroBits | Leading zero bits required on every incoming event for proof of work. Defaults to zero. Disabled when set to zero. |
105104
| limits.event.kind.blacklist | List of event kinds to always reject. Leave empty to allow any. |
106105
| limits.event.kind.whitelist | List of event kinds to always allow. Leave empty to allow any. |
107106
| limits.event.pubkey.blacklist | List of public keys to always reject. Public keys in this list will not be able to post to this relay. |
108-
| limits.event.pubkey.minLeadingZeroBits | Leading zero bits required on the public key of incoming events for proof of work. |
109-
| | Defaults to zero. Disabled when set to zero. |
107+
| limits.event.pubkey.minLeadingZeroBits | Leading zero bits required on the public key of incoming events for proof of work. Defaults to zero. Disabled when set to zero. |
110108
| limits.event.pubkey.whitelist | List of public keys to always allow. Only public keys in this list will be able to post to this relay. Use for private relays. |
111109
| limits.event.rateLimits[].kinds | List of event kinds rate limited. Use `[min, max]` for ranges. Optional. |
112110
| limits.event.rateLimits[].period | Rate limiting period in milliseconds. |

resources/default-settings.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ nip05:
5555
domainBlacklist: []
5656
network:
5757
maxPayloadSize: 524288
58-
# Comment the next line if using CloudFlare proxy
59-
remoteIpHeader: x-forwarded-for
60-
# Optional: only trust forwarding headers from these proxy IPs
61-
trustedProxies: []
62-
# Uncomment the next line if using CloudFlare proxy
58+
# Uncomment only when using a trusted reverse proxy and configuring trustedProxies.
59+
# remoteIpHeader: x-forwarded-for
6360
# remoteIpHeader: cf-connecting-ip
61+
# Proxy IPs allowed to set remoteIpHeader (loopback and common docker internal)
62+
trustedProxies:
63+
- "127.0.0.1"
64+
- "::ffff:127.0.0.1"
65+
- "::1"
66+
- "10.10.10.1"
67+
- "::ffff:10.10.10.1"
6468
workers:
6569
count: 0
6670
mirroring:

src/utils/http.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { IncomingMessage } from 'http'
22

33
import { Settings } from '../@types/settings'
44

5+
let warnedEmptyTrustedProxies = false
6+
7+
export const _resetWarnings = (): void => { warnedEmptyTrustedProxies = false }
8+
59
const normalizeIpAddress = (input: string): string => {
610
if (input.startsWith('::ffff:')) {
711
return input.slice(7)
@@ -36,13 +40,13 @@ export const getRemoteAddress = (request: IncomingMessage, settings: Settings):
3640
}
3741

3842
const trustedProxies = settings.network?.trustedProxies
39-
if (header && (!Array.isArray(trustedProxies) || trustedProxies.length === 0)) {
43+
if (header && (!Array.isArray(trustedProxies) || trustedProxies.length === 0) && !warnedEmptyTrustedProxies) {
4044
console.warn('WARNING: network.remoteIpHeader is set but network.trustedProxies is empty. Forwarded headers will be ignored. Add your proxy IP to network.trustedProxies.')
45+
warnedEmptyTrustedProxies = true
4146
}
4247

43-
const headerAddress = header
44-
? request.headers[header]
45-
: undefined
48+
const rawHeaderAddress = header ? request.headers[header] : undefined
49+
const headerAddress = Array.isArray(rawHeaderAddress) ? rawHeaderAddress[0] : rawHeaderAddress
4650
const socketAddress = request.socket.remoteAddress
4751

4852
const trustedProxy = typeof socketAddress === 'string'

0 commit comments

Comments
 (0)