Skip to content
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

fix: retrieve client IP from X-Forwarded-For header #428

Merged
merged 1 commit into from
Dec 19, 2023
Merged

Conversation

xav
Copy link
Contributor

@xav xav commented Dec 19, 2023

Description

Since the migration moved the service behind an ALB, we cannot retrieve the client IP directly for geo-location.
This leverages the X-Forwarded-For header injected by the LB instead.

How Has This Been Tested?

Unit tests

Due Diligence

  • Breaking change
  • Requires a documentation update
  • Requires a e2e/integration test update

Copy link
Member

@chris13524 chris13524 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to use axum_client_ip instead for this?

Copy link
Member

@arein arein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use a library to abstract this away in Verify API or somewhere else - maybe @xDarksome or @chris13524 know?

But as a hotfix this shouldn't wait for that - can improve later

@xDarksome
Copy link
Member

You mean this? https://github.com/WalletConnect/verify-server/blob/main/src/http_server/mod.rs#L26
I think @xav was the one who added it 😄

Copy link
Contributor

@geekbrother geekbrother left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the comment.

.get("X-Forwarded-For")
.and_then(|header| header.to_str().ok())
.and_then(|header| header.split(',').next())
.and_then(|client_ip| client_ip.trim().parse::<IpAddr>().ok())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks scary not to handle any errors here. Malformed X-Forwarded-For can lead to 500 errors without any debug information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't the and_then chain default to an Error and ultimately to a None if anything goes wrong?

@xav
Copy link
Contributor Author

xav commented Dec 19, 2023

You mean this? https://github.com/WalletConnect/verify-server/blob/main/src/http_server/mod.rs#L26 I think @xav was the one who added it 😄

Yeah, I added it but

  • I forgot about it and wanted to fix the issue ASAP
  • honestly, I don't really like it, it feels a bit overkill just for the LBA issue. We might need to assess how correct we want the resolved IP to be, and in the case we want it to be correct, I think we need to "map" the network to configure the resolver.

@xav
Copy link
Contributor Author

xav commented Dec 19, 2023

Might be nice to use axum_client_ip instead for this?

It's a hotfix and I think it should have the same end result. But we can overhaul this after.

@xav xav merged commit 306ad07 into master Dec 19, 2023
1 check passed
@xav xav deleted the fix/alb_metrics branch December 19, 2023 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants