-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Prevent reflective invocation of private methods in web dispatcher #35352
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: yongjunhong <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be checked in RequestMappingHandlerMapping
when request mappings are being initialized?
It would avoid repeating that on every call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I requested a few changes.
Please also take Rossen's comment into account.
spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
Outdated
Show resolved
Hide resolved
spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
Outdated
Show resolved
Hide resolved
...ng-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java
Outdated
Show resolved
Hide resolved
...ng-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java
Outdated
Show resolved
Hide resolved
I'm currently traveling, so I should be able to work on it around Wednesday or Thursday this week. |
Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
Please take a look :) |
If you have some time, I’d really appreciate it if you could take a look at this PR as well. 🙇🏻♂️🙇🏻♂️ It’s similar to the this PR, focusing on the access modifiers and proxies!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the requested changes. It's looking better. 👍
I've requested a few additional changes in this follow up review.
Also, please make analogous changes to org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping
and org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMappingTests
.
String methodPackageName = (methodPackage != null) ? methodPackage.getName() : "default package"; | ||
String handlerPackageName = (handlerPackage != null) ? handlerPackage.getName() : "default package"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe java.lang.Package.getName()
can return null
on Java 17.
throw new IllegalStateException( | ||
"Package-private method [" + method + "] on CGLIB proxy class [" + declaringClass.getName() + | ||
"] from package [" + methodPackageName + "] cannot be advised when used by handler class [" + | ||
handlerType.getName() + "] from package [" + handlerPackageName + "] because it is effectively private. " + | ||
"Either make the method public/protected or use interface-based JDK proxying instead."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please introduce a test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in dba200f !
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert all unnecessary changes to this file.
protected @Nullable RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { | ||
int modifiers = method.getModifiers(); | ||
|
||
if (isCglibProxy(handlerType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better if we extract this new CGLIB-proxy validation to a separate helper method in order not to clutter getMappingForMethod()
.
...java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
Outdated
Show resolved
Hide resolved
...org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java
Outdated
Show resolved
Hide resolved
...org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java
Outdated
Show resolved
Hide resolved
...org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java
Outdated
Show resolved
Hide resolved
...org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java
Outdated
Show resolved
Hide resolved
...org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java
Outdated
Show resolved
Hide resolved
…c/method/annotation/RequestMappingHandlerMapping.java Co-authored-by: Sam Brannen <[email protected]> Signed-off-by: Yongjun Hong <[email protected]>
…c/method/annotation/RequestMappingHandlerMappingTests.java Co-authored-by: Sam Brannen <[email protected]> Signed-off-by: Yongjun Hong <[email protected]>
…c/method/annotation/RequestMappingHandlerMappingTests.java Co-authored-by: Sam Brannen <[email protected]> Signed-off-by: Yongjun Hong <[email protected]>
…c/method/annotation/RequestMappingHandlerMappingTests.java Co-authored-by: Sam Brannen <[email protected]> Signed-off-by: Yongjun Hong <[email protected]>
…c/method/annotation/RequestMappingHandlerMappingTests.java Co-authored-by: Sam Brannen <[email protected]> Signed-off-by: Yongjun Hong <[email protected]>
…c/method/annotation/RequestMappingHandlerMappingTests.java Co-authored-by: Sam Brannen <[email protected]> Signed-off-by: Yongjun Hong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
…related tests Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
Signed-off-by: yongjunhong <[email protected]>
fixes #30938