Vamsi-klu commented on code in PR #18975:
URL: https://github.com/apache/pinot/pull/18975#discussion_r3817445955


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/AuthenticationFilter.java:
##########
@@ -130,35 +142,70 @@ AccessType extractAccessType(Method endpointMethod) {
     return AccessType.READ;
   }
 
+  /// Resolves the table `endpointMethod` acts on, or `null` when the request 
addresses the cluster rather than a
+  /// table. `AccessControlUtils.validatePermission` picks the table-scoped or 
the cluster-wide check on that answer,
+  /// so it must not be steerable by the caller.
+  ///
+  /// Path parameters are template variables of the endpoint's own `@Path`, 
hence part of its declaration. Query
+  /// parameters are caller-supplied and JAX-RS surfaces every one present on 
the URI, so only those the endpoint
+  /// declares may name the table: otherwise a caller could append 
`?tableName=<a table it is scoped to>` to a cluster
+  /// endpoint and have it authorized as a table-scoped request.
+  @Nullable
   @VisibleForTesting
   static String extractTableName(Method endpointMethod, MultivaluedMap<String, 
String> pathParameters,
       MultivaluedMap<String, String> queryParameters) {
     Authorize authorize = endpointMethod.getAnnotation(Authorize.class);
     if (authorize != null && authorize.targetType() == TargetType.TABLE) {
-      return FineGrainedAuthUtils.findRawTargetId(authorize, pathParameters, 
queryParameters);
+      // The annotation names the parameter, but it is only trustworthy where 
the endpoint also binds it.
+      MultivaluedMap<String, String> trustedQueryParameters =
+          declaredQueryParams(endpointMethod).contains(authorize.paramName()) 
? queryParameters
+              : new MultivaluedHashMap<>();
+      return FineGrainedAuthUtils.findRawTargetId(authorize, pathParameters, 
trustedQueryParameters);
     }
-    return extractTableName(pathParameters, queryParameters);
-  }
-
-  @VisibleForTesting
-  static String extractTableName(MultivaluedMap<String, String> pathParameters,
-      MultivaluedMap<String, String> queryParameters) {
     String tableName = extractTableName(pathParameters);
     if (tableName != null) {
       return tableName;
     }
-    return extractTableName(queryParameters);
+    Set<String> declaredQueryParams = declaredQueryParams(endpointMethod);
+    for (String key : TABLE_NAME_KEYS) {
+      if (queryParameters.containsKey(key) && 
declaredQueryParams.contains(key)) {
+        return queryParameters.getFirst(key);
+      }
+    }
+    return null;

Review Comment:
   Good catch, and I kept it as a note rather than a behavior change. Declared 
is treated as “this parameter may name the table,” which is only safe when the 
endpoint actually scopes the operation with it. GET 
/tasks/task/{taskName}/debug only filters subtasks. Task-level state still 
comes back, so ?tableName=A still lets a principal scoped to A read metadata 
for a task on B. Master already trusted that parameter, so this is not a 
regression. I added that caveat to extractTableName and to the description so 
the next cluster endpoint with an optional tableName does not copy the pattern 
by accident.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to