Repository navigation
TEZ-4754: RelocalizationUtils: input handling improvements - #537
abstractdog wants to merge 2 commits into
Conversation
|
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
🟡 Changes recommended
URI-scheme traversal and submission-state corruption remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Tightens destination filename validation for relocalized AM resources and adds unit coverage.
Changes:
- Rejects empty, path-based, absolute, and traversal-like names.
- Adds tests for valid and invalid destination names.
File summaries
| File | Description |
|---|---|
tez-common/src/test/java/org/apache/tez/dag/utils/TestRelocalizationUtils.java |
Adds coverage for accepted and rejected destination names. |
tez-common/src/main/java/org/apache/tez/dag/utils/RelocalizationUtils.java |
Validates destination names before downloading resources. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (destName.indexOf('/') >= 0 || destName.indexOf('\\') >= 0 | ||
| || destName.indexOf('\0') >= 0) { | ||
| throw new IllegalArgumentException( | ||
| "Resource name must not contain path separators: " + destName); | ||
| } | ||
| if (destName.equals(".") || destName.equals("..")) { | ||
| throw new IllegalArgumentException( | ||
| "Resource name must not be a parent-directory reference: " + destName); | ||
| } | ||
| if (new Path(destName).isAbsolute()) { |
There was a problem hiding this comment.
not true, adding a unit test to prove: uriSchemeOpaqueFormIsRejected
new Path(destName) call inside RelocalizationUtils#validateDestName already throwsIllegalArgumentException from Hadoop's URI parser in such cases
| // absolute path, a path separator, or a ".." segment — so a submitter | ||
| // holding AM modify access cannot land a jar anywhere on the AM host and | ||
| // chain it into code execution via the classloader / am-hooks path. | ||
| validateDestName(destName); |
There was a problem hiding this comment.
ack, handling with an upfront check
650be89 to
5ce77fb
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
🎊 +1 overall
This message was automatically generated. |
ayushtkn
left a comment
There was a problem hiding this comment.
Thanx @abstractdog for the fix.
Banning / and : rejects resource keys with subdirectories (lib/foo.jar) and names with a colon, both of which work today. Is this intended?
| if (destName.indexOf('/') >= 0 || destName.indexOf('\\') >= 0 | ||
| || destName.indexOf('\0') >= 0) { | ||
| throw new IllegalArgumentException( | ||
| "Resource name must not contain path separators: " + destName); | ||
| } |
There was a problem hiding this comment.
I think we also need to reject : here (destName.indexOf(':') >= 0) and use a single "illegal characters" message.
Opaque forms like file:.. and C:evil.jar should be rejected explicitly. Right now they are rejected only because new Path(destName) throws. On Windows (Path.WINDOWS), new Path("C:evil.jar") doesn't throw and isAbsolute() is false, so that name would pass.
| if (new Path(destName).isAbsolute()) { | ||
| throw new IllegalArgumentException( | ||
| "Resource name must not be absolute: " + destName); | ||
| } |
There was a problem hiding this comment.
Can be dropped once : is rejected. Leading / and \ are already covered by the separator check, and drive-absolute forms by :. This new Path(destName) call is also what made the check platform-dependent.
| // Validate before startDAGExecution mutates currentDAG and amResources: | ||
| // a later failure would leave the session stuck "already running a DAG". | ||
| if (additionalResources != null) { | ||
| try { | ||
| RelocalizationUtils.validateDestNames(additionalResources.keySet()); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new TezException(e); | ||
| } | ||
| } |
There was a problem hiding this comment.
Could we add a test that a rejected submission leaves currentDAG and amResources untouched? That is the main claim in the comment above this block.
Tighten validation of the destination file name used when downloading additional AM resources so unexpected shapes are rejected before the file is written. Adds a small unit test. Co-Authored-By: Claude Code <noreply@anthropic.com>
- validateDestName: allow relative subdirectories (e.g. lib/foo.jar), which work today, while rejecting absolute names and any empty, '.' or '..' segment. - Reject ':' explicitly under a single "illegal characters" message, together with '\' and NUL, so opaque/drive forms like "file:.." and "C:evil.jar" are refused on every platform. - Drop the new Path(destName).isAbsolute() check: leading '/' is covered by the absolute check and drive-absolute forms by ':', and it made the validation platform-dependent. - Add a DAGAppMaster test that a rejected submission leaves currentDAG and amResources untouched.
good catch, that wasn't the intention names with relative subdirectories like lib/foo.jar are accepted again, names are still rejected if they start with / or contain an empty, . or .. segment (so lib/../x, ./x, a//b and lib/ all fail) |
5ce77fb to
1ec17ff
Compare
|
🎊 +1 overall
This message was automatically generated. |
Tighten validation of the destination file name used when downloading additional AM resources so unexpected shapes are rejected before the file is written. Adds a small unit test.