Skip to content

Java: add Gson support to unsafe-deserialization query#6463

Merged
aschackmull merged 12 commits intogithub:mainfrom
smowton:smowton/admin/gson-unsafe-deserialization
Oct 12, 2021
Merged

Java: add Gson support to unsafe-deserialization query#6463
aschackmull merged 12 commits intogithub:mainfrom
smowton:smowton/admin/gson-unsafe-deserialization

Conversation

@smowton
Copy link
Contributor

@smowton smowton commented Aug 10, 2021

Based on #6456 -- please only review the top two commits here.

Since the original by @luchua-bc added models of some Android functions I've ported the existing Android models to CSV and generated tests for them here.

@smowton smowton requested a review from a team as a code owner August 10, 2021 16:27
@smowton smowton changed the title Smowton/admin/gson unsafe deserialization Java: add Gson support to unsafe-deserialization query Aug 10, 2021
@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Android,``android.*``,18,34,70,,,3,67,,,
+    Android,``android.*``,18,135,70,,,3,67,,,
-    Others,"``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``groovy.lang``, ``groovy.util``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.json``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``",7,251,146,,,,14,18,,
+    Others,"``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.json``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``",7,262,146,,,,14,18,,
-    Totals,,84,2711,398,13,6,6,107,33,1,66
+    Totals,,84,2823,398,13,6,6,107,33,1,66
  • Changes to framework-coverage-java.csv:
- android.content,8,,4,,,,,,,,,,,,,8,,,,,,4,
+ android.content,8,,33,,,,,,,,,,,,,8,,,,,,33,
+ android.os,,,72,,,,,,,,,,,,,,,,,,,71,1
+ flexjson,,,1,,,,,,,,,,,,,,,,,,,,1
+ jodd.json,,,10,,,,,,,,,,,,,,,,,,,,10

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Android,``android.*``,18,34,70,,,3,67,,,
+    Android,``android.*``,18,145,70,,,3,67,,,
-    Others,"``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``groovy.lang``, ``groovy.util``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.json``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``",7,251,146,,,,14,18,,
+    Others,"``com.esotericsoftware.kryo.io``, ``com.esotericsoftware.kryo5.io``, ``com.fasterxml.jackson.core``, ``com.fasterxml.jackson.databind``, ``com.opensymphony.xwork2.ognl``, ``com.unboundid.ldap.sdk``, ``flexjson``, ``groovy.lang``, ``groovy.util``, ``jodd.json``, ``ognl``, ``org.apache.commons.codec``, ``org.apache.commons.jexl2``, ``org.apache.commons.jexl3``, ``org.apache.commons.ognl``, ``org.apache.directory.ldap.client.api``, ``org.apache.ibatis.jdbc``, ``org.apache.shiro.jndi``, ``org.codehaus.groovy.control``, ``org.dom4j``, ``org.hibernate``, ``org.jooq``, ``org.json``, ``org.mvel2``, ``org.xml.sax``, ``org.xmlpull.v1``, ``play.mvc``",7,262,146,,,,14,18,,
-    Totals,,84,2711,398,13,6,6,107,33,1,66
+    Totals,,84,2833,398,13,6,6,107,33,1,66
  • Changes to framework-coverage-java.csv:
- android.content,8,,4,,,,,,,,,,,,,8,,,,,,4,
+ android.content,8,,33,,,,,,,,,,,,,8,,,,,,33,
+ android.os,,,82,,,,,,,,,,,,,,,,,,,81,1
+ flexjson,,,1,,,,,,,,,,,,,,,,,,,,1
+ jodd.json,,,10,,,,,,,,,,,,,,,,,,,,10

@smowton
Copy link
Contributor Author

smowton commented Aug 11, 2021

On all the extra modelling: I've just ported the existing models here, please feel free to follow up with further modelling

atorralba
atorralba previously approved these changes Aug 11, 2021
Copy link
Contributor

@atorralba atorralba left a comment

Choose a reason for hiding this comment

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

The Gson part LGTM after resolving the comments above.

@smowton smowton force-pushed the smowton/admin/gson-unsafe-deserialization branch from 5dc0ca5 to 48c497e Compare September 10, 2021 15:35
import semmle.code.java.dataflow.DataFlow
import semmle.code.java.dataflow.ExternalFlow
import semmle.code.java.dataflow.TaintTracking
import TestUtilities.InlineExpectationsTest
Copy link
Contributor

Choose a reason for hiding this comment

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

The boilerplate here has been abstracted into java/ql/test/TestUtilities/InlineFlowTest.qll so just import that.

@smowton
Copy link
Contributor Author

smowton commented Sep 14, 2021

Suggest #6599 goes before this PR, because it includes detailed Intent models that could then be removed from this PR

@smowton smowton force-pushed the smowton/admin/gson-unsafe-deserialization branch from 48c497e to 57771e1 Compare October 7, 2021 10:53
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Android,``android.*``,45,233,70,,,3,67,,,
+    Android,``android.*``,45,344,70,,,3,67,,,
-    Totals,,143,5125,408,13,6,10,107,33,1,66
+    Totals,,143,5236,408,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- android.content,8,27,61,,,,,,,,,,,,,8,,,,,,27,,4,57
+ android.content,8,27,90,,,,,,,,,,,,,8,,,,,,27,,33,57
- android.os,,,82,,,,,,,,,,,,,,,,,,,,,2,80
+ android.os,,,164,,,,,,,,,,,,,,,,,,,,,83,81

@luchua-bc
Copy link
Contributor

Great. We are going to finalize this PR as well:-)

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Android,``android.*``,45,233,70,,,3,67,,,
+    Android,``android.*``,45,273,70,,,3,67,,,
-    Totals,,143,5125,408,13,6,10,107,33,1,66
+    Totals,,143,5165,408,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- android.os,,,82,,,,,,,,,,,,,,,,,,,,,2,80
+ android.os,,,122,,,,,,,,,,,,,,,,,,,,,41,81

* Account for changed dataflow graph shape using external flow
* Account for BaseBundle only existing as of Android 5
* Properly implement Parcelable, which we previously got away with due to a partial stub
* Restore an Android 11 function that had been added to the Android 9 Context class (I won't get into enforcing the difference in this PR)
Note these still aren't entirely mechanically generated stubs matching the real Android 9.
@smowton smowton force-pushed the smowton/admin/gson-unsafe-deserialization branch from 216dc0f to 3c96e62 Compare October 12, 2021 11:35
@smowton
Copy link
Contributor Author

smowton commented Oct 12, 2021

@aschackmull this is now updated and mergeable AFAIK

@github-actions
Copy link
Contributor

⚠️ The head of this PR and the base branch were compared for differences in the framework coverage reports. The generated reports are available in the artifacts of this workflow run. The differences will be picked up by the nightly job after the PR gets merged. The following differences were found:

java

Generated file changes for java

  • Changes to framework-coverage-java.rst:
-    Android,``android.*``,45,245,70,,,3,67,,,
+    Android,``android.*``,45,285,70,,,3,67,,,
-    Totals,,143,5217,408,13,6,10,107,33,1,66
+    Totals,,143,5257,408,13,6,10,107,33,1,66
  • Changes to framework-coverage-java.csv:
- android.os,,,82,,,,,,,,,,,,,,,,,,,,,2,80
+ android.os,,,122,,,,,,,,,,,,,,,,,,,,,41,81


/**
* Holds if `intentNode` is an `Intent` used in the context `(T)intentNode.getParcelableExtra(...)` and
* `parcelNode` is the corresponding parameter of `Parcelable.Creator<T> { public T createFromParcel(Parcel parcelNode) { }`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The qldoc should likely be extended with a tidbit like "and T is a concrete type that ..., which explains the role of T` and in particular highlights that it isn't a type variable (which one might otherwise easily assume).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@aschackmull aschackmull merged commit 0e5f89a into github:main Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants