description: 'attacker-controlled first IP',
xff: '127.0.0.1, 192.168.1.100',
expected: '192.168.1.100',
},
])(
'Should return the last IP from x-forwarded-for ($description)',
({ xff, expected }) => {
const req = new Request('http://localhost/', {
headers: { 'x-forwarded-for': xff },
})
const c = new Context(req, {
env: {
requestContext: {
elb: {
targetGroupArn: 'arn:aws:elasticloadbalancing:...',
])('Should return the last IP from x-forwarded-for ($description)', ({ xff, expected }) => {
const req = new Request('http://localhost/', {
headers: { 'x-forwarded-for': xff },
})
const c = new Context(req, {
env: {
requestContext: {
elb: {
targetGroupArn: 'arn:aws:elasticloadbalancing:...',
},
},
},
})
const info = getConnInfo(c)
expect(info.remote.address).toBe(expected)
}
)
},
})
const info = getConnInfo(c)
expect(info.remote.address).toBe(expected)
})
it('Should return undefined when no x-forwarded-for header', () => {
const c = new Context(new Request('http://localhost/'), {
env: {