Skip to content

[java] CodeQL query, Increase fastjson detection. Improve RemoteFlowSource class, support SpringMvc. #3665

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

Closed
wants to merge 3 commits into from

Conversation

haby0
Copy link
Contributor

@haby0 haby0 commented Jun 10, 2020

CodeQL query, Increase fastjson detection. Improve RemoteFlowSource class, support SpringMvc.

*/
class FastJson extends RefType {
FastJson() {
this.hasQualifiedName("com.alibaba.fastjson", "JSON") or
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should probably either change this predicate or adjust the comment to include JSONObject as well.


override predicate isSink(DataFlow::Node sink) { sink instanceof UnsafeDeserializationSink }
}

from DataFlow::PathNode source, DataFlow::PathNode sink, UnsafeDeserializationConfig conf
where conf.hasFlowPath(source, sink)
select sink.getNode().(UnsafeDeserializationSink).getMethodAccess(), source, sink,
"Unsafe deserialization of $@.", source.getNode(), "user input"
"Unsafe deserialization of $@.", source.getNode(), "user input"
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to not be autoformatted.
You can run the autoformatter from VS Code on all files.

@@ -0,0 +1,281 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels seems to be a duplicate of the existing FlowSources.qll file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don’t think so. The FlowSources.qll file is missing for SpringMVC for remote input. The SpringServletInputParameterSource class can only get the remote part of the user's input, for example the following code is in the source Won't get it.

@GetMapping(value = "index")
public void index(String request){
     System.out.println(request);
}

I added the SpringMVC class to the FlowSources.qll file, mainly to verify whether the class annotation where the method parameters are obtained uses the ``Mapping``` and sub-annotations.
You can try the above code with the following statement.

import java
import semmle.code.java.dataflow.FlowSources

from RemoteFlowSource rfs
select rfs

Copy link
Contributor

Choose a reason for hiding this comment

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

You have two FlowSources.qll files in your commit.
java/ql/src/semmle/code/java/dataflow/FlowSources.qll
and
java/ql/src/semmle/code/java/FlowSources.qll

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I have a problem with the project here and need to resubmit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello
Sorry, I added pr.
Link to the PR:[#3674]

About fastjson introduction:
https://github.com/alibaba/fastjson
Fastjson deserializes through the parse and parseObject methods, and there may be command execution vulnerabilities in deserialization.
Vulnerabilities and fixes:
https://m.sangfor.com/source/blog-network-security/1516.html
https://github.com/alibaba/fastjson/issues

@aschackmull
Copy link
Contributor

Looks like this is superseded by #3674. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants