codeant-ai-for-open-source[bot] commented on code in PR #41938:
URL: https://github.com/apache/superset/pull/41938#discussion_r3560861623


##########
superset-frontend/src/middleware/loggerMiddleware.ts:
##########
@@ -162,9 +162,10 @@ const loggerMiddleware: Middleware<
     }
     const path = navPath || window?.location?.href;
 
-    if (dashboardInfo?.id && path?.includes('/dashboard/')) {
+    const isEmbedded = path?.includes('/embedded/');
+    if (dashboardInfo?.id && (path?.includes('/dashboard/') || isEmbedded)) {
       logMetadata = {
-        source: 'dashboard',
+        source: isEmbedded ? 'embedded_dashboard' : 'dashboard',

Review Comment:
   **Suggestion:** The embedded-route detection is too broad: checking whether 
the URL contains `'/embedded/'` will also misclassify normal dashboard URLs 
when the dashboard slug is `embedded` (for example `/dashboard/embedded/`). 
This will incorrectly tag regular dashboard events as embedded events. Use 
pathname-based route matching (for actual embedded patterns like 
`/dashboard/:idOrSlug/embedded/` or `/embedded/:uuid/`) instead of a generic 
substring check. [incorrect condition logic]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ⚠️ Regular dashboard 'embedded' mislogged as embedded_dashboard in events.
   ⚠️ Analytics using source field misreport embedded dashboard usage.
   ⚠️ Audit logs conflate embedded and regular dashboard traffic.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Create or edit a dashboard so its slug is `embedded`, using the 
`Dashboard.slug` field
   defined at `superset/models/dashboard.py:144` and noting that URLs are 
generated as
   `/superset/dashboard/{slug or id}/` in `Dashboard.url` at
   `superset/models/dashboard.py:199-200`.
   
   2. Access the regular dashboard URL `/superset/dashboard/embedded/`, which 
is served by
   the `dashboard` view exposed at `/dashboard/<dashboard_id_or_slug>/` in
   `superset/views/core.py:779-785`, causing SPA navigation to this dashboard 
in the
   frontend.
   
   3. In the SPA, a LOG_EVENT action with `eventName: 
LOG_ACTIONS_SPA_NAVIGATION` and
   `eventData.path: '/dashboard/embedded/'` is dispatched (matching the pattern 
used in
   `superset-frontend/src/middleware/logger.test.ts:113-115`), and this action 
flows through
   the Redux middleware imported as `logger` from 
`src/middleware/loggerMiddleware` at
   `superset-frontend/src/middleware/logger.test.ts:19-25`.
   
   4. Inside `loggerMiddleware` at
   `superset-frontend/src/middleware/loggerMiddleware.ts:160-169`, `path` 
resolves to
   `'/dashboard/embedded/'` (lines 160-163), `isEmbedded` is set to `true` via
   `path?.includes('/embedded/')` (line 165), and because `dashboardInfo.id` is 
truthy and
   the path also includes `/dashboard/`, the condition on line 166 runs and
   `logMetadata.source` is set to `'embedded_dashboard'` on line 168, causing 
subsequent
   events for this regular dashboard to be logged and sent via `sendBeacon` 
(lines 93-123) as
   if they originated from an embedded dashboard.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=34771d378d7f463c8041ef5fe9eba437&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=34771d378d7f463c8041ef5fe9eba437&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/middleware/loggerMiddleware.ts
   **Line:** 165:168
   **Comment:**
        *Incorrect Condition Logic: The embedded-route detection is too broad: 
checking whether the URL contains `'/embedded/'` will also misclassify normal 
dashboard URLs when the dashboard slug is `embedded` (for example 
`/dashboard/embedded/`). This will incorrectly tag regular dashboard events as 
embedded events. Use pathname-based route matching (for actual embedded 
patterns like `/dashboard/:idOrSlug/embedded/` or `/embedded/:uuid/`) instead 
of a generic substring check.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41938&comment_hash=88a6e2c4006536d9ac27c8ea296cd861868e30159df9cd5d9cc666e167ac768f&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41938&comment_hash=88a6e2c4006536d9ac27c8ea296cd861868e30159df9cd5d9cc666e167ac768f&reaction=dislike'>👎</a>



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