Skip to content

TEZ-4753: ShuffleHandler: input handling improvements - #536

Open
abstractdog wants to merge 2 commits into
apache:masterfrom
abstractdog:TEZ-4753
Open

abstractdog wants to merge 2 commits into
apache:masterfrom
abstractdog:TEZ-4753

Conversation

@abstractdog

Copy link
Copy Markdown
Contributor

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.

@abstractdog
abstractdog requested a lite review from Copilot September 18, 2026 12:32
@tez-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 3m 13s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ master Compile Tests _
+1 💚 mvninstall 3m 18s master passed
+1 💚 compile 2m 45s master passed
+1 💚 checkstyle 0m 20s master passed
+1 💚 javadoc 0m 14s master passed
+0 🆗 spotbugs 0m 34s tez-plugins/tez-aux-services in master has 5 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚 mvninstall 2m 23s the patch passed
+1 💚 codespell 0m 52s No new issues.
+1 💚 compile 2m 47s the patch passed
+1 💚 javac 2m 47s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 0m 15s /results-checkstyle-tez-plugins_tez-aux-services.txt tez-plugins/tez-aux-services: The patch generated 1 new + 78 unchanged - 0 fixed = 79 total (was 78)
+1 💚 javadoc 0m 14s the patch passed
+1 💚 spotbugs 0m 43s the patch passed
_ Other Tests _
+1 💚 unit 60m 57s root in the patch passed.
+1 💚 asflicense 0m 22s The patch does not generate ASF License warnings.
80m 2s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/1/artifact/out/Dockerfile
Optional Tests dupname compile unit asflicense javac javadoc spotbugs checkstyle codespell detsecrets
uname Linux c2eaded8c330 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality tez-personality.sh
git revision master / 0e9f756
Default Java Eclipse Adoptium-21.0.12+8-LTS
Test Results https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/1/testReport/
Max. process+thread count 1503 (vs. ulimit of 5500)
modules C: tez-plugins/tez-aux-services U: tez-plugins/tez-aux-services
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.3 codespell=2.4.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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, and map/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.

Comment on lines +1208 to +1221
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;
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Comment on lines +1912 to +1913
conn = (HttpURLConnection) URI.create(
base + "/mapOutput?job=job_12345_1&dag=1&reduce=1&map="

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Comment on lines +1205 to +1207
private boolean validateShufflePathParams(ChannelHandlerContext ctx,
List<String> dagIdQ, List<String> vertexIdQ, List<String> mapIds,
boolean isDeleteRequest) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

@tez-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 8s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ master Compile Tests _
+1 💚 mvninstall 3m 7s master passed
+1 💚 compile 2m 30s master passed
+1 💚 checkstyle 0m 21s master passed
+1 💚 javadoc 0m 19s master passed
+0 🆗 spotbugs 0m 34s tez-plugins/tez-aux-services in master has 5 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚 mvninstall 2m 14s the patch passed
+1 💚 codespell 0m 50s No new issues.
+1 💚 compile 2m 27s the patch passed
+1 💚 javac 2m 27s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 0m 18s /results-checkstyle-tez-plugins_tez-aux-services.txt tez-plugins/tez-aux-services: The patch generated 1 new + 78 unchanged - 0 fixed = 79 total (was 78)
+1 💚 javadoc 0m 19s the patch passed
+1 💚 spotbugs 0m 38s the patch passed
_ Other Tests _
+1 💚 unit 60m 30s root in the patch passed.
+1 💚 asflicense 0m 19s The patch does not generate ASF License warnings.
75m 39s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/2/artifact/out/Dockerfile
Optional Tests dupname compile unit asflicense javac javadoc spotbugs checkstyle codespell detsecrets
uname Linux c6cf5f0a2556 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality tez-personality.sh
git revision master / 0e9f756
Default Java Eclipse Adoptium-21.0.12+8-LTS
Test Results https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/2/testReport/
Max. process+thread count 1447 (vs. ulimit of 5500)
modules C: tez-plugins/tez-aux-services U: tez-plugins/tez-aux-services
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/2/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.3 codespell=2.4.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

@ayushtkn ayushtkn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanx @abstractdog for the fix, few comments rest LGTM

Comment on lines +1881 to +1882
assertTrue(code >= 400 && code < 600,
"Expected an error response for traversing dag, got " + code);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, bad ids are already rejected with a 400 before we get there

Comment on lines +1754 to +1755
shuffleBaseURL + "/mapOutput?job=job_12345_0001&dag=1&reduce=1&map=attempt_12345_1_m_1_0").toURL();
shuffleHandler.secretManager.addTokenForJob("job_12345_0001",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and testDuplicateDagOrVertexParamIsRejected share ~30 lines of identical ShuffleHandler scaffolding (init, token, start). A shared helper method would help reduce duplication

abstractdog and others added 2 commits November 30, 2026 13:25
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.
@tez-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 0s Docker mode activated.
-1 ❌ docker 1m 56s Docker failed to build run-specific yetus/tez:tp-28876}.
Subsystem Report/Notes
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/3/console
versions git=2.34.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

@abstractdog
abstractdog requested a review from ayushtkn November 30, 2026 13:01
@abstractdog

abstractdog commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 0s Docker mode activated.
-1 ❌ docker 1m 56s Docker failed to build run-specific yetus/tez:tp-28876}.
Subsystem Report/Notes
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/3/console
versions git=2.34.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org
This message was automatically generated.

14:01:37  #12 108.4 Err:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
14:01:37  #12 108.4   Could not connect to archive.ubuntu.com:80 (185.125.190.83), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.81), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.82), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.81), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.24), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.22), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.92.23), connection timed out Could not connect to archive.ubuntu.com:80 (185.125.190.82), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.83), connection timed out [IP: 185.125.190.83 80]
14:01:37  #12 108.4 Err:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
14:01:37  #12 108.4   Unable to connect to archive.ubuntu.com:80: [IP: 185.125.190.83 80]

archive.ubuntu.com is down, will retry later

Screenshot 2026-11-30 at 14 08 25

@tez-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 0s Docker mode activated.
-1 ❌ docker 2m 27s Docker failed to build run-specific yetus/tez:tp-16853}.
Subsystem Report/Notes
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-536/4/console
versions git=2.34.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants