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

add java doc warning comment into ipAddressMatcher for potential DNS resolution #13621

Conversation

maoling
Copy link

@maoling maoling commented Aug 7, 2023

  • In our use case, our api gateway used ipAddressMatcher util to check whether a request's ip is in the ip-black list, but sometimes, the remoteAddress or X-Forwarded-For is in a bad format(maybe malicious requests) as following. They're not Ip, but hostname. ipAddressMatcher calls the InetAddress#getByName which causes a DNS resolution, then the cloud vm alarms with this behavior.

    remoteAddress:cj3gg4k0jvnb2t86jq6gi8twr36r38hzd.oast.fun:44194, X-Forwarded
    -For:"cj3gg4k0jvnb2t86jq6gi8twr36r38hzd.oast.fun, 1.2.3.4, 1.4.5.6"

  • This PR just adds java doc warning comment, If your guys prefer the implementation by removing using the InetAddress#getByName and check ipv4/ipv6 inside, I will create another PR to rewrite it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 7, 2023
@jzheaux jzheaux self-assigned this Oct 3, 2023
@jzheaux jzheaux added in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 3, 2023
Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

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

I don't think the new JavaDoc adds anything that wasn't already said earlier. The existing JavaDoc says:

* Takes a specific IP address or a range specified using the IP/Netmask (e.g.
* 192.168.1.0/24 or 202.24.0.0/14).

so the correct format is already indicated.

That said, I like your second idea to validate the parameters. Will you please change the code to validate that the first character is [, :, or a digit? Something like this:

Assert.isTrue(ipAddress.charAt(0) == `[` || 
    ipAddress.charAt(0) == ':' || 
    Character.digit(ipAddress.charAt(0), 16), "ipAddress must start with a [, :, or a hexadecimal digit");

This is needed in the constructor as well as the matches(String) method when preparing the address for comparison.

@jzheaux
Copy link
Contributor

jzheaux commented Oct 31, 2023

Hi, @maoling. Are you able to make the requested changes?

@jzheaux jzheaux added the status: ideal-for-contribution An issue that we actively are looking for someone to help us with label Dec 8, 2023
@jzheaux jzheaux removed their assignment Dec 8, 2023
FdHerrera pushed a commit to FdHerrera/spring-security that referenced this pull request Jan 25, 2024
@FdHerrera
Copy link

Hi guys, hope you're doing well

Since no updates has been made in this pull request, I went ahead and created this PR to address the changes suggested.

Let me know if its ok for you

@jzheaux jzheaux removed the status: ideal-for-contribution An issue that we actively are looking for someone to help us with label Jan 30, 2024
@jzheaux jzheaux self-assigned this Jan 30, 2024
@jzheaux jzheaux added the status: duplicate A duplicate of another issue label Jan 30, 2024
@jzheaux
Copy link
Contributor

jzheaux commented Jan 30, 2024

Closing in favor of #14491

@jzheaux jzheaux closed this Jan 30, 2024
FdHerrera pushed a commit to FdHerrera/spring-security that referenced this pull request Jan 30, 2024
jzheaux pushed a commit that referenced this pull request Jan 31, 2024
@jzheaux jzheaux added this to the 6.3.0-M2 milestone May 30, 2024
sara9674 referenced this pull request Aug 18, 2024
I went through everything to get it to fit with Spring's docuemntation standard.
Lots of small changes for punctuation, grammar, usage, voice, and so on.
Also added some links, mostly to the API Javadoc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants