Skip to content

Commit

Permalink
Tune client IP detection (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 authored and fs5m8 committed Dec 31, 2022
1 parent c94ecfd commit 88b8c0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ autoAdmin: true
#mediaProxy: https://example.com/proxy

# Sign to ActivityPub GET request (default: true)
#signToActivityPubGet: flase
#signToActivityPubGet: false

# Allowed network address (default: all allowed)
#allowedPrivateNetworks: [
Expand All @@ -145,3 +145,7 @@ autoAdmin: true

# Hide server infomation (default: false)
#hideServerInfo: true

# Header for get original IP address from reverse proxy
# ex. X-Forwarded-For, CF-Connecting-IP
#proxyIpHeader: 'X-Forwarded-For'
2 changes: 2 additions & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export type Source = {
mediaProxy?: string;

signToActivityPubGet?: boolean;

proxyIpHeader?: string;
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const serverLogger = new Logger('server', 'gray', false);

// Init app
const app = new Koa();

app.proxy = true;
(app as any).maxIpsCount = 1;
(app as any).proxyIpHeader = config.proxyIpHeader ?? 'X-Forwarded-For';

if (!['production', 'test'].includes(process.env.NODE_ENV || '')) {
// Logger
Expand Down

0 comments on commit 88b8c0f

Please sign in to comment.