Skip to content

feat: util getRequestIP #503

Merged
pi0 merged 13 commits intomainfrom
feat/get-request-ip
Aug 14, 2023
Merged

feat: util getRequestIP #503
pi0 merged 13 commits intomainfrom
feat/get-request-ip

Conversation

@harlan-zw
Copy link
Copy Markdown
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
Copy Markdown

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
Comment thread src/utils/request.ts Outdated
Comment thread src/utils/request.ts Outdated
@pi0
Copy link
Copy Markdown
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 :)

@atinux
Copy link
Copy Markdown
Contributor

atinux commented Aug 11, 2023

Nice!

I like getRequestIP()

@danielroe
Copy link
Copy Markdown
Member

Agreed on getRequestIP 👍

And nice work.

Comment thread test/utils.test.ts
Comment thread src/utils/request.ts Outdated
@harlan-zw harlan-zw changed the title feat: util getRequestIp feat: util getRequestIP Aug 11, 2023
@harlan-zw
Copy link
Copy Markdown
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.

Comment thread src/utils/request.ts
@pi0 pi0 merged commit 588c8a3 into main Aug 14, 2023
@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