-
Notifications
You must be signed in to change notification settings - Fork 291
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
Fix dependency resolution for nested JARs (with fix for Spring Boot) #6720
Conversation
BenchmarksStartupParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 43 metrics, 11 unstable metrics. LoadParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 12 metrics, 14 unstable metrics. Request duration reports for insecure-bankgantt
title insecure-bank - request duration [CI 0.99] : candidate=1.31.0-SNAPSHOT~6c582788d6, baseline=1.31.0-SNAPSHOT~a718db98d8
dateFormat X
axisFormat %s
section baseline
no_agent (367.919 µs) : 348, 388
. : milestone, 368,
iast (469.793 µs) : 449, 490
. : milestone, 470,
iast_FULL (532.882 µs) : 512, 553
. : milestone, 533,
iast_GLOBAL (503.251 µs) : 481, 526
. : milestone, 503,
iast_HARDCODED_SECRET_DISABLED (471.104 µs) : 451, 491
. : milestone, 471,
iast_INACTIVE (448.893 µs) : 428, 469
. : milestone, 449,
iast_TELEMETRY_OFF (470.709 µs) : 450, 492
. : milestone, 471,
tracing (445.491 µs) : 425, 466
. : milestone, 445,
section candidate
no_agent (366.407 µs) : 346, 386
. : milestone, 366,
iast (477.585 µs) : 457, 498
. : milestone, 478,
iast_FULL (537.312 µs) : 517, 558
. : milestone, 537,
iast_GLOBAL (507.966 µs) : 485, 531
. : milestone, 508,
iast_HARDCODED_SECRET_DISABLED (468.446 µs) : 448, 489
. : milestone, 468,
iast_INACTIVE (445.544 µs) : 425, 466
. : milestone, 446,
iast_TELEMETRY_OFF (464.909 µs) : 444, 486
. : milestone, 465,
tracing (445.649 µs) : 425, 466
. : milestone, 446,
Request duration reports for petclinicgantt
title petclinic - request duration [CI 0.99] : candidate=1.31.0-SNAPSHOT~6c582788d6, baseline=1.31.0-SNAPSHOT~a718db98d8
dateFormat X
axisFormat %s
section baseline
no_agent (1.351 ms) : 1332, 1370
. : milestone, 1351,
appsec (1.804 ms) : 1780, 1828
. : milestone, 1804,
iast (1.523 ms) : 1500, 1547
. : milestone, 1523,
profiling (1.544 ms) : 1521, 1568
. : milestone, 1544,
tracing (1.505 ms) : 1481, 1528
. : milestone, 1505,
section candidate
no_agent (1.346 ms) : 1327, 1365
. : milestone, 1346,
appsec (1.785 ms) : 1761, 1809
. : milestone, 1785,
iast (1.519 ms) : 1496, 1542
. : milestone, 1519,
profiling (1.585 ms) : 1561, 1610
. : milestone, 1585,
tracing (1.513 ms) : 1489, 1536
. : milestone, 1513,
|
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.
LGTM
1c81258
to
9e899dc
Compare
e70344e
to
37f798c
Compare
try { | ||
JarReader.Extracted metadata = null; | ||
String path = null; | ||
if ("file".equals(scheme)) { | ||
File f; | ||
if (uri.isOpaque()) { | ||
f = new File(uri.getSchemeSpecificPart()); |
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.
What is the reason of doing it like this instead of:
File f = Paths.get(uri).toFile();
I think this part is not covered by any test 😢
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.
The background story here is tricky, so I'm not touching this logic until I can test it properly. We'll probably require Windows tests for it. See #4820
if (innerJarPath.endsWith("!/")) { | ||
innerJarPath = innerJarPath.substring(0, innerJarPath.length() - 2); | ||
} | ||
try (final JarFile outerJar = new JarFile(outerJarPath, false /* no verify */)) { |
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.
Out of curiosity, but is it a thing to have more levels of nested jars?
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 have seen at least 1 user report at Spring Boot asking about a third level of nesting, but Spring Boot does not support that. It would definitely be possible to do it with a custom URLConnection
handler. But until we find some real scenario, I would rather not implement it.
Also note that, while it should be relatively easy to add support for an arbitrary nesting depth, we would always set a limit to nesting for performance reasons since each additional level of nesting needs to decompress a stream.
37f798c
to
4637775
Compare
4637775
to
6c58278
Compare
What Does This Do
Motivation
Additional Notes
Jira ticket: APPSEC-51864
Original error reproduction
In the intermediate commits, you will find a test case reproducing the original error as well as a naive fix:
JarUrlConnection
cachingJarFile
instances. Under certain order of actions, we would close the sameJarFile
instance while the application is using it to read something from it, causing an exception. Now we force disable the use of caching on our side withsetUseCaches(false)
.A test failure here would look like this (e.g. if you revert the last commit in this PR, which contains the actual fix):
Benchmarks
Master, no full scanning of nested dependencies:
Naive solution, re-using Spring's JAR URLConnection handler:
Final state, with our own JAR reader: