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

feat: util getRequestIP #503

Merged
merged 13 commits into from
Aug 14, 2023
Merged

feat: util getRequestIP #503

merged 13 commits into from
Aug 14, 2023

Conversation

harlan-zw
Copy link
Contributor

@harlan-zw harlan-zw commented Aug 10, 2023

πŸ”— Linked issue

#272

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

We should make it convenient for users to get the client request ip while being able to opt-in to trust the x-forwarded-for header.

Currently, users are implementing themselves:

I'm also open to naming this getClientIp or getRequestClientIp.

This utility does open the door for trusting spoofable headers (see nuxt-security), sorting that is out of the scope of this utility, I'll open this as a seperate issue.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Merging #503 (b688b22) into main (f3d0bc9) will decrease coverage by 0.02%.
Report is 2 commits behind head on main.
The diff coverage is 80.64%.

@@            Coverage Diff             @@
##             main     #503      +/-   ##
==========================================
- Coverage   82.41%   82.40%   -0.02%     
==========================================
  Files          31       31              
  Lines        3549     3580      +31     
  Branches      528      531       +3     
==========================================
+ Hits         2925     2950      +25     
- Misses        624      630       +6     
Files Changed Coverage Ξ”
src/utils/request.ts 92.77% <79.31%> (-2.59%) ⬇️
src/types.ts 100.00% <100.00%> (ΓΈ)

@harlan-zw harlan-zw changed the title feat: add getRequestIp util feat: util getRequestIp Aug 10, 2023
src/utils/request.ts Outdated Show resolved Hide resolved
src/utils/request.ts Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Aug 11, 2023

Thanks for PR! I love it it is a must have util!

/cc @danielroe @atinux @antfu about naming ideas. I like the current getRequestI^P btw :)

Copy link
Member

atinux commented Aug 11, 2023

Nice!

I like getRequestIP()

Copy link
Member

Agreed on getRequestIP πŸ‘

And nice work.

src/utils/request.ts Outdated Show resolved Hide resolved
@harlan-zw harlan-zw changed the title feat: util getRequestIp feat: util getRequestIP Aug 11, 2023
@harlan-zw
Copy link
Contributor Author

harlan-zw commented Aug 11, 2023

With the introduction of this utility, it's important to consider this issue #504

As you can see, it's common for module authors to be trusting easily spoofed headers atm.

@pi0 pi0 merged commit 588c8a3 into main Aug 14, 2023
5 of 6 checks passed
@pi0 pi0 deleted the feat/get-request-ip branch August 14, 2023 09:49
@pi0 pi0 mentioned this pull request Aug 14, 2023
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.

5 participants