-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add x-forwarded-for to PDS-proxied requests to entryway #3553
base: main
Are you sure you want to change the base?
Conversation
const result: T | HeadersParam = params ?? { headers: {} } | ||
if (ip) { | ||
result.headers['x-forwarded-for'] = ip | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more accurate (in terms of semantics of that header), and easier/efficient, to simply add the req.socket.remoteAddress
to the already provided list of x-forwarded-for
? (req.ip
is a getter which we could avoid calling by doing this)
Another option would be to use req.ips.join(', ')
in order to reveal all the (untrusted) proxies the request went through. Again, just as a matter of respecting the semantics of that header.
The reason it might be relevant to keep all the forwarded IPs is in case of a bad actor using a public proxy service. We would log only the public proxy's ip, and discard the IP of the bad actor (assuming the public proxy properly generates the forwarded for header).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the catchall handler (pipethrough) does not apply this. Is this on purpose?
await ctx | ||
.serviceAuthHeaders( | ||
recipientDid, | ||
ctx.cfg.entryway.did, | ||
ids.ComAtprotoAdminSendEmail, | ||
) | ||
.then((x) => forwardIp(req, x)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add dedicated methods that do this?
ctx.entrywayServiceAuthHeaders(req, did, lxm)
ctx.entrywayPassthruAuthHeaders(req)
It makes it less likely, in the future, that someone forgets to forward the ip when proxying towards entryway, don't you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you missed one/two spot:
authPassthru(reqCtx.req), |
atproto/packages/pds/tests/entryway.test.ts
Lines 120 to 124 in 75c05d5
await pds.ctx.serviceAuthHeaders( | |
alice, | |
'did:example:entryway', | |
'com.atproto.identity.updateHandle', | |
), |
As advertised: adding x-forwarded-for to PDS-proxied requests to entryway.
Can get rid of some minor noise in review by ignoring whitespace changes.