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

optimization parseIP in xff #1915

Merged
merged 3 commits into from
Mar 18, 2025
Merged

optimization parseIP in xff #1915

merged 3 commits into from
Mar 18, 2025

Conversation

007gzs
Copy link
Collaborator

@007gzs 007gzs commented Mar 18, 2025

Ⅰ. Describe what this PR did

optimization parseIP in xff
xff 分割符为 [英文逗号+空格],应该在提取后做trim操作(取第一个值其实理论没有问题)
parseIP函数中未支持多ip的处理,原有test case5中127.0.0.1:12,[fe80::14d5:8aff:fed9:2114]:123是正好第一个ip带了端口才通过,如果是 127.0.0.1,[fe80::14d5:8aff:fed9:2114]:123的话就会获取到127.0.0.1,[fe80的结果

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.74%. Comparing base (ef31e09) to head (f40e148).
Report is 357 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1915      +/-   ##
==========================================
+ Coverage   35.91%   43.74%   +7.83%     
==========================================
  Files          69       78       +9     
  Lines       11576    12479     +903     
==========================================
+ Hits         4157     5459    +1302     
+ Misses       7104     6678     -426     
- Partials      315      342      +27     

see 73 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


if from_header {
source = strings.Trim(strings.Split(source, ",")[0], " ")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

虽然可以用,但逻辑上是怪怪的,为什么 fromHeader 就需要先 split,来自别的地方就不需要呢?还是说逻辑上是因为某些来源的数据可能会包含多个值,需要做 split。是不是外部传一个 separator 更合适?如果separator 为空,就不做 split。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

按照之前代码逻辑也是只有从Header中获取的ip才进行split https://github.com/alibaba/higress/pull/1915/files#diff-7c4a88bf97556c8363af8dc954fe2bfa077fc5b0122a4349e6e52c5a5be5eee1L102-L106
其实应该是只有xff才支持多ip,需要做split操作,理论上remontAddr 和 real-ip 都不支持多ip(real-ip不是标准该规范)
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For

Copy link
Collaborator

@CH3CHO CH3CHO left a comment

Choose a reason for hiding this comment

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

LGTM

@CH3CHO CH3CHO merged commit 029c3e7 into alibaba:main Mar 18, 2025
12 checks passed
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.

3 participants