This repository was archived by the owner on Jul 6, 2026. It is now read-only.
[src] Fix LGTM-reported issues. - #1074
Merged
Merged
Conversation
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Jan 12, 2023
Context: dotnet/java-interop#1074 Does It Build™?
Remember CodeQL (5a0097b)? CodeQL basically runs [GitHub LGTM][0] on source code, looking for possible security issues. Now that CodeQL is running, we can begin addressing reported issues. Problems found include: * Result of call that may return NULL dereferenced unconditionally * HttpClient created with CheckCertificateRevocationList disabled * Arbitrary file write during archive extraction ("Zip Slip") * Local-user-controlled data in path expression ~~ Result of call that may return NULL dereferenced unconditionally ~~ If **calloc**(3) returns `nullptr`, we shouldn't pass it on to `MultiByteToWideChar()` or `WideCharToMultiByte()` without validation. ~~ HttpClient created with CheckCertificateRevocationList disabled ~~ Apparently the `HttpClient` default constructor is "bad"; we should instead use the [`HttpClient(HttpMessageHandler)` constructor][1], provide our own `HttpClientHandler`, and ensure that [`HttpClientHandler.CheckCertificateRevocationList`][2] is True. ~~ Arbitrary file write during archive extraction ("Zip Slip") ~~ `tools/java-source-utils` (69e1b80) extracts the `.java` files within `.jar`/`.aar`/.etc files to use for type resolution, as I couldn't find an easier way to get `com.github.javaparser` to use Java source code for type resolution purposes unless the Java source code was on-disk. Unfortunately, the `.jar` extraction code was susceptible to "Zip Slip", wherein an entry in the `.jar` may overwrite unexpected files if it has an entry name of e.g. `../../this/is/really/bad.java`. Fix this by verifying that the target filename stays within the target directory structure, and skip the entry when the name is invalid. ~~ Local-user-controlled data in path expression ~~ LGTM is complaining that `tools/java-source-utils` (69e1b80) accepts user-controlled data. These warnings will be *ignored* because the app is *unusable* without "user-controlled data"; consider these `java-source-utils --help` fragments: Java type resolution options: --bootclasspath CLASSPATH ':'-separated list of .jar files to use for type resolution. -a, --aar FILE .aar file to use for type resolution. -j, --jar FILE .jar file to use for type resolution. -s, --source DIR Directory containing .java files for type resolution purposes. DOES NOT parse all files. These are all user-controlled, and they are necessary to allow `java-source-utils` to *work*. Similarly: Output file options: -P, --output-params FILE Write method parameter names to FILE. -D, --output-javadoc FILE Write Javadoc within XML container to FILE. LGTM complains that `--output-javadoc FILE` accepts a user-controlled path which may control directory separator chars, and *this is intentional*; using it would be annoying if that weren't true! These uses can be ignored by appending the comment `// lgtm [java/path-injection-local]`. [0]: https://github.com/marketplace/lgtm [1]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.-ctor?view=netstandard-2.0#system-net-http-httpclient-ctor(system-net-http-httpmessagehandler) [2]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.checkcertificaterevocationlist?view=net-7.0
jonpryor
force-pushed
the
jonp-lgtm-fixes-20230111
branch
from
January 12, 2023 16:36
97658c6 to
cc96072
Compare
jonpryor
pushed a commit
to dotnet/android
that referenced
this pull request
Jan 24, 2023
Changes: dotnet/java-interop@cf80deb...1366d99 * dotnet/java-interop@1366d998: [Java.Interop.Tools.JavaCallableWrappers] use less System.Linq for CAs (dotnet/java-interop#1072) * dotnet/java-interop@bde306d5: [Java.Interop.Tools.JavaCallableWrappers] JavaTypeScanner.GetJavaTypes (dotnet/java-interop#1076) * dotnet/java-interop@f03088e7: [Java.Interop.Tools.JavaCallableWrappers] IMetadataResolver redux (dotnet/java-interop#1075) * dotnet/java-interop@e11d0242: [lgtm] Fix LGTM-reported issues. (dotnet/java-interop#1074) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remember CodeQL (5a0097b)? CodeQL basically runs GitHub LGTM on source code, looking for possible security issues.
Now that CodeQL is running, we can begin addressing reported issues.
Problems found include:
~~ Result of call that may return NULL dereferenced unconditionally ~~
If calloc(3) returns
nullptr, we shouldn't pass it on toMultiByteToWideChar()orWideCharToMultiByte()without validation.~~ HttpClient created with CheckCertificateRevocationList disabled ~~
Apparently the
HttpClientdefault constructor is "bad"; we should instead use theHttpClient(HttpMessageHandler)constructor, provide our ownHttpClientHandler, and ensure thatHttpClientHandler.CheckCertificateRevocationListis True.~~ Arbitrary file write during archive extraction ("Zip Slip") ~~
tools/java-source-utils(69e1b80) extracts the contents of.jarfiles to look for.javafiles to use for type resolution, as I couldn't find an easier way to getcom.github.javaparserto use Java source code for type resolution purposes unless the Java source code was on-disk. Unfortunately, the.jarextraction code was susceptible to "Zip Slip", wherein an entry in the.jarmay overwrite unexpected data if it has an entry name of e.g.../../this/is/really/bad. Fix this by verifying that the target filename stays within the target directory structure.~~ Local-user-controlled data in path expression ~~
LGTM is complaining that
tools/java-source-utils(69e1b80) accepts user-controlled data. These warnings will be ignored because the app is unusable without "user-controlled data"; consider thesejava-source-utils --helpfragments:These are all user-controlled, and they are necessary to allow
java-source-utilsto work.Similarly:
LGTM complains that
--output-javadoc FILEaccepts a user-controlled path which may control directory separator chars, and this is intentional; using it would be annoying if that weren't true!These uses can be ignored by appending the comment
// lgtm [java/path-injection-local].