fix: dashboard preview thumbnails fail for guest API calls during screenshot - #1205
fix: dashboard preview thumbnails fail for guest API calls during screenshot#1205Neeraaaj wants to merge 1 commit into
Conversation
|
Tick the box to add this pull request to the merge queue (same as
|
Confidence Score: 4/5The preview-key permission path needs a fix before merging.
insights/api/shared.py
|
| Filename | Overview |
|---|---|
| frontend/src2/dashboard/DashboardCard.vue | Adds local image error state and resets it when the preview URL changes. |
| insights/api/shared.py | Expands preview-key lookup to query params and cookies, but the validation remains unscoped. |
| insights/insights/doctype/insights_dashboard_v3/insights_dashboard_v3.py | Uses the preview key for Guest dashboard API access and soft-fails screenshot generation. |
| insights/www/insights.py | Sets a temporary preview-key cookie so the Guest SPA can call APIs during screenshot capture. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
insights/api/shared.py:58-64
**Preview Key Becomes Global**
When a screenshot key is present in the query string or cookie, this check only verifies that the cache entry exists. Since generated keys store only `True`, the same key can make Guest requests pass `is_public()` and `get_distinct_column_values()` for unrelated private dashboards until the key is deleted or expires.
Reviews (1): Last reviewed commit: "fix: dashboard preview thumbnails fail f..." | Re-trigger Greptile
| # used to generate preview images of a dashboard | ||
| preview_key = frappe.request.headers.get("X-Insights-Preview-Key") | ||
| preview_key = ( | ||
| frappe.request.headers.get("X-Insights-Preview-Key") | ||
| or frappe.form_dict.get("insights_preview_key") | ||
| or frappe.request.cookies.get("insights_preview_key") | ||
| ) | ||
| return preview_key and frappe.cache.get_value(f"insights_preview_key:{preview_key}") |
There was a problem hiding this comment.
When a screenshot key is present in the query string or cookie, this check only verifies that the cache entry exists. Since generated keys store only True, the same key can make Guest requests pass is_public() and get_distinct_column_values() for unrelated private dashboards until the key is deleted or expires.
Context Used: This is a Frappe Framework application (Python bac... (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: insights/api/shared.py
Line: 58-64
Comment:
**Preview Key Becomes Global**
When a screenshot key is present in the query string or cookie, this check only verifies that the cache entry exists. Since generated keys store only `True`, the same key can make Guest requests pass `is_public()` and `get_distinct_column_values()` for unrelated private dashboards until the key is deleted or expires.
**Context Used:** This is a Frappe Framework application (Python bac... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
How can I resolve this? If you propose a fix, please make it concise.
Before:-

After:-
