Repository navigation
TEZ-4753: ShuffleHandler: input handling improvements - #536
abstractdog wants to merge 2 commits into
Conversation
|
🎊 +1 overall
This message was automatically generated. |
There was a problem hiding this comment.
🟡 Changes recommended
Query-parameter “shape” validation is still incomplete (multiple dag/vertex values) and the new test should use a consistent valid job id to avoid false-positive coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR strengthens ShuffleHandler HTTP query parameter validation to block path-traversal vectors (dag/vertex/map) before any filesystem path construction or delete/read operations occur, and adds a regression test to cover traversal attempts.
Changes:
- Added strict regex validation for
dag,vertex, andmap/attempt identifiers to prevent traversal components from reaching path concatenation logic. - Added early request rejection (400) for malformed structural parameters.
- Added a regression test that issues delete/read requests with traversing values and asserts they are rejected and do not delete out-of-scope files.
File summaries
| File | Description |
|---|---|
| tez-plugins/tez-aux-services/src/main/java/org/apache/tez/auxservices/ShuffleHandler.java | Adds parameter pattern validation to prevent path traversal via shuffle query parameters and attempt-id handling. |
| tez-plugins/tez-aux-services/src/test/java/org/apache/tez/auxservices/TestShuffleHandler.java | Adds a regression test covering traversal attempts in dag, vertex, and map query parameters. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 3
- 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 (dagIdQ != null && !dagIdQ.isEmpty()) { | ||
| String dagId = dagIdQ.get(0); | ||
| if (dagId == null || !DAG_ID_PATTERN.matcher(dagId).matches()) { | ||
| sendError(ctx, "Bad dag parameter", BAD_REQUEST); | ||
| return false; | ||
| } | ||
| } | ||
| if (vertexIdQ != null && !vertexIdQ.isEmpty()) { | ||
| String vertexId = vertexIdQ.get(0); | ||
| if (vertexId == null || !VERTEX_ID_PATTERN.matcher(vertexId).matches()) { | ||
| sendError(ctx, "Bad vertex parameter", BAD_REQUEST); | ||
| return false; | ||
| } | ||
| } |
| conn = (HttpURLConnection) URI.create( | ||
| base + "/mapOutput?job=job_12345_1&dag=1&reduce=1&map=" |
| private boolean validateShufflePathParams(ChannelHandlerContext ctx, | ||
| List<String> dagIdQ, List<String> vertexIdQ, List<String> mapIds, | ||
| boolean isDeleteRequest) { |
6967579 to
e5cb36f
Compare
|
🎊 +1 overall
This message was automatically generated. |
ayushtkn
left a comment
There was a problem hiding this comment.
Thanx @abstractdog for the fix, few comments rest LGTM
| assertTrue(code >= 400 && code < 600, | ||
| "Expected an error response for traversing dag, got " + code); |
There was a problem hiding this comment.
These range assertions would also pass on a 500 or a file-not-found failure, so they don't show the validation is what rejects the request. I think we should assert exactly 400 here.
The same applies at lines below as well
There was a problem hiding this comment.
ack, it's important, especially as it's the point ot the patch itself
| for (String mapId : s.split(",")) { | ||
| // Self-defending sink: reject values that could escape the output dir. | ||
| if (mapId == null || !ATTEMPT_ID_PATTERN.matcher(mapId).matches()) { | ||
| throw new IOException("Invalid mapId: " + mapId); |
There was a problem hiding this comment.
This isn't an I/O failure, so IllegalArgumentException fits better.
| // directory listing; keep the accepted form strict. | ||
| if (taskAttemptId == null | ||
| || !ATTEMPT_ID_PATTERN.matcher(taskAttemptId).matches()) { | ||
| LOG.warn("Ignoring taskAttempt delete for invalid attempt id: {}", taskAttemptId); |
There was a problem hiding this comment.
splitMaps already rejects invalid ids, so this branch can't run. If it ever did, it would skip the delete and still return 200. Maybe we shold drop this check, or fail the request with a 400.
There was a problem hiding this comment.
removed, bad ids are already rejected with a 400 before we get there
| shuffleBaseURL + "/mapOutput?job=job_12345_0001&dag=1&reduce=1&map=attempt_12345_1_m_1_0").toURL(); | ||
| shuffleHandler.secretManager.addTokenForJob("job_12345_0001", |
There was a problem hiding this comment.
by accident, of course :) reverting this
| Collections.addAll(ret, s.split(",")); | ||
| for (String mapId : s.split(",")) { | ||
| // Self-defending sink: reject values that could escape the output dir. | ||
| if (mapId == null || !ATTEMPT_ID_PATTERN.matcher(mapId).matches()) { |
There was a problem hiding this comment.
I think after s.split, mapId can't be null, String Split I guess guraneets non-null elements
| /** Traversal-shaped dag/vertex/map params must be rejected. */ | ||
| @Test | ||
| @Timeout(value = 10000, unit = TimeUnit.MILLISECONDS) | ||
| public void testTraversalInDagVertexMapIsRejected() throws Exception { |
There was a problem hiding this comment.
this and testDuplicateDagOrVertexParamIsRejected share ~30 lines of identical ShuffleHandler scaffolding (init, token, start). A shared helper method would help reduce duplication
Tighten validation of the dag, vertex and map query parameters in the shuffle handler so unexpected shapes are rejected up front rather than carried into filesystem path construction. Also reject requests where dag or vertex is present more than once, since downstream code only reads the first occurrence and a permissive validator would let a submitter pair a benign first value with a hostile second one. Adds regression tests. Co-Authored-By: Claude Code <noreply@anthropic.com>
- splitMaps: throw IllegalArgumentException instead of IOException (not an I/O failure) and drop the redundant null check (String.split never yields null elements). - deleteTaskAttemptDirectories: drop the unreachable attempt id check; the ids come from splitMaps, which already rejects invalid values with a 400. - Tests: assert exactly 400 instead of any 4xx/5xx, extract shared ShuffleHandler setup (built on getShuffleHandlerWithNoVerify) and request helpers, reuse getResponseCode in testUnauthenticatedDeleteIsRejected, use a consistent job id, add a traversing taskAttempt delete case, and revert the unrelated job id change in testShuffleHandlerSendsDiskError.
e5cb36f to
157fb5f
Compare
|
💔 -1 overall
This message was automatically generated. |
archive.ubuntu.com is down, will retry later
|
|
💔 -1 overall
This message was automatically generated. |

Tighten validation of the dag, vertex and map query parameters in the shuffle handler so unexpected shapes are rejected up front rather than carried into filesystem path construction. Adds a regression test.