gnodet commented on code in PR #2079:
URL: https://github.com/apache/maven-resolver/pull/2079#discussion_r3893108440
##########
maven-resolver-transport-file/src/main/java/org/eclipse/aether/transport/file/FileTransporter.java:
##########
@@ -163,10 +163,22 @@ protected void implPut(PutTask task) throws Exception {
private Path getPath(TransportTask task, boolean required) throws
Exception {
String path = task.getLocation().getPath();
- if (path.contains("../")) {
+ if (path == null) {
+ throw new IllegalArgumentException("illegal resource path: null");
+ }
+ Path relative = fileSystem.getPath(path);
+ if (relative.isAbsolute()) {
+ throw new IllegalArgumentException("illegal resource path: " +
path);
+ }
+ for (Path segment : relative) {
+ if ("..".equals(segment.toString())) {
+ throw new IllegalArgumentException("illegal resource path: " +
path);
+ }
+ }
+ Path file = basePath.resolve(relative).normalize();
+ if (!file.startsWith(basePath.normalize())) {
Review Comment:
Good catch — moved `normalize()` into the ctor (`this.basePath =
requireNonNull(basePath).normalize()`). The containment check now uses
`basePath` directly. Also fixed `@since 2.0.22` → `2.0.23` across the PR.
##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/BasedirNameMapper.java:
##########
@@ -93,11 +93,26 @@ public Collection<NamedLockKey> nameLocks(
: DirectoryUtils.resolveDirectory(session,
DEFAULT_LOCKS_DIR, CONFIG_PROP_LOCKS_DIR, false);
return delegate.nameLocks(session, artifacts, metadatas).stream()
- .map(k -> NamedLockKey.of(
-
basedir.resolve(k.name()).toAbsolutePath().toUri().toASCIIString(),
k.resources()))
+ .map(k -> NamedLockKey.of(resolveContained(basedir,
k.name()), k.resources()))
.collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
+
+ /**
+ * Resolves the delegate-provided lock name against the locks base
directory, rejecting any name that would
+ * escape it. Lock names are derived from artifact coordinates that arrive
from remote repositories; a name
+ * containing path traversal must never select a lock file outside the
locks directory, as locks are created
+ * (and deleted on close) by the file lock factory at the resolved path.
+ *
+ * @since 2.0.22
+ */
+ private static String resolveContained(Path basedir, String name) {
+ Path resolved = basedir.resolve(name).toAbsolutePath();
+ if
(!resolved.normalize().startsWith(basedir.toAbsolutePath().normalize())) {
Review Comment:
Same fix applied here: `basePath` is now normalized at construction time
(`path.toAbsolutePath().normalize()`), and the session-resolved fallback path
is also normalized. `resolveContained()` now just does `resolve().normalize()`
+ `startsWith(basedir)` without redundant per-call normalization.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]