You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2025/10/09 17:39:21 UTC
[PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
eschutho opened a new pull request, #35584:
URL: https://github.com/apache/superset/pull/35584
### SUMMARY
Replaces iframe-based resource export with fetch API and blob downloads to prevent Content Security Policy (CSP) `frame-src` violations.
**The Problem:**
The previous export implementation created hidden iframes to trigger downloads, which violates strict CSP policies that set `frame-src 'none'`. This resulted in console errors:
```
Refused to frame '...' because it violates the following Content Security Policy directive: "frame-src 'none'"
```
**The Solution:**
- Use `SupersetClient.get()` with `parseMethod: 'raw'` to fetch export files as blobs
- Parse `Content-Disposition` headers for proper filenames
- Programmatically create download links and trigger them
- Add proper async/await error handling with user-friendly toast messages
**Benefits:**
- ✅ No CSP violations - never attempts to frame URLs
- ✅ Better error handling - catches and displays errors to users
- ✅ Consistent with existing patterns - follows same approach as dashboard screenshot downloads
- ✅ Works with strict Content Security Policies
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
**Before:** Browser console shows CSP violation errors when exporting dashboards/charts
**After:** Exports work cleanly without CSP violations
### TESTING INSTRUCTIONS
1. **Setup**: Ensure your Superset instance has a strict CSP configured (or use browser dev tools to simulate)
2. **Test Dashboard Export**:
- Go to Dashboard List (`/dashboard/list/`)
- Select one or more dashboards
- Click "Export" from the actions menu or bulk actions
- Verify the ZIP file downloads successfully
- Check browser console - no CSP errors should appear
3. **Test Chart Export**:
- Go to Chart List (`/chart/list/`)
- Select one or more charts
- Click "Export"
- Verify download and no console errors
4. **Test Other Resource Types**:
- Repeat for Datasets, Databases, Saved Queries, and Themes
5. **Test Error Handling**:
- Use network throttling or mock a failed API response
- Verify error toast appears with helpful message
- Verify loading state clears properly
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags: None
- [ ] Changes UI: No (backend behavior only)
- [ ] Includes DB Migration: No
- [ ] Introduces new feature or API: No
- [ ] Removes existing feature or API: No
**Files Changed:**
- `superset-frontend/src/utils/export.ts` - Core export utility (iframe → fetch)
- `superset-frontend/src/utils/export.test.ts` - Comprehensive unit tests
- 8 files - Updated export handlers with async/await and error handling:
- DashboardList, ChartList, DatasetList, DatabaseList
- SavedQueryList, ThemeList, ChartTable, DashboardTable
**Test Coverage:**
- Unit tests cover success paths, error cases, and edge cases
- Tests verify correct API calls, blob handling, filename parsing, and cleanup
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387865776
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18392759857) for [8a64618](https://github.com/apache/superset/commit/8a64618)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387900941
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18393004881) for [513fc30](https://github.com/apache/superset/commit/513fc30)
• **Environment:** http://34.214.76.175:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387041620
@eschutho can we add tests to `superset-frontend/src/features/home/ChartTable.test.tsx` and `superset-frontend/src/features/home/DashboardTable.test.tsx` such that when we hit the export button the spinner shows up and we make a call to export with the expected id? I think that may be a gap we have missing with testing right now.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387447420
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18388518407) for [22afa04](https://github.com/apache/superset/commit/22afa04)
• **Environment:** http://35.86.96.225:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387810698
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18392189448) for [6c11c49](https://github.com/apache/superset/commit/6c11c49)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387881875
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18392759857) for [8a64618](https://github.com/apache/superset/commit/8a64618)
• **Environment:** http://52.27.2.184:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3392431772
I'll fast-follow with more tests.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387729675
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18391135866) for [9afd760](https://github.com/apache/superset/commit/9afd760)
• **Environment:** http://34.221.79.224:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387427544
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18388574884) for [c1f9541](https://github.com/apache/superset/commit/c1f9541)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35584:
URL: https://github.com/apache/superset/pull/35584#discussion_r2421707644
##########
superset-frontend/src/features/home/DashboardTable.tsx:
##########
@@ -118,12 +118,17 @@ function DashboardTable({
setLoaded(true);
}, [activeTab]);
- const handleBulkDashboardExport = (dashboardsToExport: Dashboard[]) => {
+ const handleBulkDashboardExport = async (dashboardsToExport: Dashboard[]) => {
const ids = dashboardsToExport.map(({ id }) => id);
- handleResourceExport('dashboard', ids, () => {
- setPreparingExport(false);
- });
setPreparingExport(true);
+ try {
+ await handleResourceExport('dashboard', ids, () => {
+ setPreparingExport(false);
+ });
+ } catch (error) {
Review Comment:
Same question as above. Do we have a test that handles this part?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho merged PR #35584:
URL: https://github.com/apache/superset/pull/35584
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387858873
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18392486087) for [efe10ec](https://github.com/apache/superset/commit/efe10ec)
• **Environment:** http://54.149.169.191:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387886801
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18393004881) for [513fc30](https://github.com/apache/superset/commit/513fc30)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387711956
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18391135866) for [9afd760](https://github.com/apache/superset/commit/9afd760)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35584:
URL: https://github.com/apache/superset/pull/35584#discussion_r2418207967
##########
superset-frontend/src/features/home/ChartTable.test.tsx:
##########
@@ -115,3 +115,49 @@ test('renders mine tab on click', async () => {
expect(screen.getAllByText(/cool chart/i)).toHaveLength(3);
});
});
+
+test('handles chart export with correct ID and shows spinner', async () => {
+ const mockExport = jest.fn().mockImplementation(() => {
+ // Simulate async export that takes some time
+ return new Promise(resolve => setTimeout(resolve, 100));
+ });
+
+ jest.mock('src/utils/export', () => ({
Review Comment:
Should this be inside the test body? In `DashboardTable.test.tsx` it's outside so wondering which is correct.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387823636
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18392189448) for [6c11c49](https://github.com/apache/superset/commit/6c11c49)
• **Environment:** http://16.144.36.101:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387030858
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18385260437) for [252f306](https://github.com/apache/superset/commit/252f306)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387146923
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18386178625) for [da61031](https://github.com/apache/superset/commit/da61031)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3391740791
The `await` is necessary here to properly manage the loading spinner state. We need to ensure `setPreparingExport(false)` is only called after the export completes (or fails). Without `await`, the spinner would disappear immediately before the download actually happens.
There's no sequential vs parallel processing issue because `handleResourceExport` is only called once with all selected dashboard IDs - the backend creates a single zip file containing all dashboards in one API call. For example, if a user selects 3 dashboards to export, we call:
```typescript
handleResourceExport('dashboard', [1, 2, 3], callback)
```
This makes a single request to `/api/v1/dashboard/export/?q=!(1,2,3)` which returns one zip file with all three dashboards.
The same pattern applies to all other `handleResourceExport` calls throughout the PR - they're all exporting a collection of IDs in a single API call.
(Comment from @elizabeththompson via Claude Code)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387076557
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18385260437) for [252f306](https://github.com/apache/superset/commit/252f306)
• **Environment:** http://34.216.57.196:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #35584:
URL: https://github.com/apache/superset/pull/35584#discussion_r2417494571
##########
superset-frontend/src/utils/export.ts:
##########
@@ -16,34 +16,60 @@
* specific language governing permissions and limitations
* under the License.
*/
-import parseCookie from 'src/utils/parseCookie';
+import { SupersetClient, logging } from '@superset-ui/core';
import rison from 'rison';
-import { nanoid } from 'nanoid';
+import contentDisposition from 'content-disposition';
import { ensureAppRoot } from './pathUtils';
-export default function handleResourceExport(
+export default async function handleResourceExport(
resource: string,
ids: number[],
done: () => void,
- interval = 200,
-): void {
- const token = nanoid();
- const url = ensureAppRoot(
- `/api/v1/${resource}/export/?q=${rison.encode(ids)}&token=${token}`,
+): Promise<void> {
+ const endpoint = ensureAppRoot(
+ `/api/v1/${resource}/export/?q=${rison.encode(ids)}`,
);
- // create new iframe for export
- const iframe = document.createElement('iframe');
- iframe.style.display = 'none';
- iframe.src = url;
- document.body.appendChild(iframe);
+ try {
+ // Use fetch with blob response instead of iframe to avoid CSP frame-src violations
+ const response = await SupersetClient.get({
+ endpoint,
+ headers: {
+ Accept: 'application/zip, application/x-zip-compressed, text/plain',
+ },
+ parseMethod: 'raw',
+ });
- const timer = window.setInterval(() => {
- const cookie: { [cookieId: string]: string } = parseCookie();
- if (cookie[token] === 'done') {
- window.clearInterval(timer);
- document.body.removeChild(iframe);
- done();
+ // Parse filename from Content-Disposition header
+ const disposition = response.headers.get('Content-Disposition');
+ let fileName = `${resource}_export.zip`;
+
+ if (disposition) {
+ try {
+ const parsed = contentDisposition.parse(disposition);
+ if (parsed?.parameters?.filename) {
+ fileName = parsed.parameters.filename;
+ }
+ } catch (error) {
+ logging.warn('Failed to parse Content-Disposition header:', error);
+ }
}
- }, interval);
+
+ // Convert response to blob and trigger download
+ const blob = await response.blob();
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = fileName;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
Review Comment:
### Unnecessary DOM layout thrashing <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
Synchronous DOM manipulation with appendChild/removeChild causes unnecessary layout thrashing for the download trigger.
###### Why this matters
The browser performs layout calculations when adding and immediately removing the anchor element, which is wasteful since the element is never meant to be visible.
###### Suggested change ∙ *Feature Preview*
Use a more efficient approach that avoids DOM manipulation:
```typescript
const a = document.createElement('a');
a.href = url;
a.download = fileName;
a.style.display = 'none';
a.click();
```
Or use the modern approach:
```typescript
if ('showSaveFilePicker' in window) {
// Use File System Access API when available
} else {
// Fallback to current approach
}
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fc9c882b-b0eb-4f77-b218-117a8723f669/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fc9c882b-b0eb-4f77-b218-117a8723f669?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fc9c882b-b0eb-4f77-b218-117a8723f669?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fc9c882b-b0eb-4f77-b218-117a8723f669?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/fc9c882b-b0eb-4f77-b218-117a8723f669)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:7b7271ec-7f28-4c84-bfcb-fe24163ee3a1 -->
[](7b7271ec-7f28-4c84-bfcb-fe24163ee3a1)
##########
superset-frontend/src/utils/export.ts:
##########
@@ -16,34 +16,60 @@
* specific language governing permissions and limitations
* under the License.
*/
-import parseCookie from 'src/utils/parseCookie';
+import { SupersetClient, logging } from '@superset-ui/core';
import rison from 'rison';
-import { nanoid } from 'nanoid';
+import contentDisposition from 'content-disposition';
import { ensureAppRoot } from './pathUtils';
-export default function handleResourceExport(
+export default async function handleResourceExport(
resource: string,
ids: number[],
done: () => void,
- interval = 200,
-): void {
- const token = nanoid();
- const url = ensureAppRoot(
- `/api/v1/${resource}/export/?q=${rison.encode(ids)}&token=${token}`,
+): Promise<void> {
+ const endpoint = ensureAppRoot(
+ `/api/v1/${resource}/export/?q=${rison.encode(ids)}`,
);
- // create new iframe for export
- const iframe = document.createElement('iframe');
- iframe.style.display = 'none';
- iframe.src = url;
- document.body.appendChild(iframe);
+ try {
+ // Use fetch with blob response instead of iframe to avoid CSP frame-src violations
+ const response = await SupersetClient.get({
+ endpoint,
+ headers: {
+ Accept: 'application/zip, application/x-zip-compressed, text/plain',
+ },
+ parseMethod: 'raw',
+ });
- const timer = window.setInterval(() => {
- const cookie: { [cookieId: string]: string } = parseCookie();
- if (cookie[token] === 'done') {
- window.clearInterval(timer);
- document.body.removeChild(iframe);
- done();
+ // Parse filename from Content-Disposition header
+ const disposition = response.headers.get('Content-Disposition');
+ let fileName = `${resource}_export.zip`;
+
+ if (disposition) {
+ try {
+ const parsed = contentDisposition.parse(disposition);
+ if (parsed?.parameters?.filename) {
+ fileName = parsed.parameters.filename;
+ }
+ } catch (error) {
+ logging.warn('Failed to parse Content-Disposition header:', error);
+ }
}
- }, interval);
+
+ // Convert response to blob and trigger download
+ const blob = await response.blob();
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = fileName;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ window.URL.revokeObjectURL(url);
Review Comment:
### Mixed responsibilities <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The file download logic is mixed with the resource export logic, violating the Single Responsibility Principle.
###### Why this matters
This mixing of concerns makes the code less reusable and harder to test. The file download functionality could be needed elsewhere and should be separated.
###### Suggested change ∙ *Feature Preview*
```typescript
// Extract to separate utility function
async function downloadBlob(blob: Blob, fileName: string): Promise<void> {
const url = window.URL.createObjectURL(blob);
try {
const a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} finally {
window.URL.revokeObjectURL(url);
}
}
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/284f416e-112a-4eec-ba90-ca52b55d8ef1/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/284f416e-112a-4eec-ba90-ca52b55d8ef1?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/284f416e-112a-4eec-ba90-ca52b55d8ef1?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/284f416e-112a-4eec-ba90-ca52b55d8ef1?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/284f416e-112a-4eec-ba90-ca52b55d8ef1)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:0da801e4-8a2d-4d3d-98f6-05cf9448db01 -->
[](0da801e4-8a2d-4d3d-98f6-05cf9448db01)
##########
superset-frontend/src/utils/export.ts:
##########
@@ -16,34 +16,60 @@
* specific language governing permissions and limitations
* under the License.
*/
-import parseCookie from 'src/utils/parseCookie';
+import { SupersetClient, logging } from '@superset-ui/core';
import rison from 'rison';
-import { nanoid } from 'nanoid';
+import contentDisposition from 'content-disposition';
import { ensureAppRoot } from './pathUtils';
-export default function handleResourceExport(
+export default async function handleResourceExport(
resource: string,
ids: number[],
done: () => void,
- interval = 200,
-): void {
- const token = nanoid();
- const url = ensureAppRoot(
- `/api/v1/${resource}/export/?q=${rison.encode(ids)}&token=${token}`,
+): Promise<void> {
+ const endpoint = ensureAppRoot(
+ `/api/v1/${resource}/export/?q=${rison.encode(ids)}`,
);
- // create new iframe for export
- const iframe = document.createElement('iframe');
- iframe.style.display = 'none';
- iframe.src = url;
- document.body.appendChild(iframe);
+ try {
+ // Use fetch with blob response instead of iframe to avoid CSP frame-src violations
+ const response = await SupersetClient.get({
+ endpoint,
+ headers: {
+ Accept: 'application/zip, application/x-zip-compressed, text/plain',
+ },
+ parseMethod: 'raw',
+ });
- const timer = window.setInterval(() => {
- const cookie: { [cookieId: string]: string } = parseCookie();
- if (cookie[token] === 'done') {
- window.clearInterval(timer);
- document.body.removeChild(iframe);
- done();
+ // Parse filename from Content-Disposition header
+ const disposition = response.headers.get('Content-Disposition');
+ let fileName = `${resource}_export.zip`;
+
+ if (disposition) {
+ try {
+ const parsed = contentDisposition.parse(disposition);
+ if (parsed?.parameters?.filename) {
+ fileName = parsed.parameters.filename;
+ }
+ } catch (error) {
+ logging.warn('Failed to parse Content-Disposition header:', error);
+ }
}
- }, interval);
+
+ // Convert response to blob and trigger download
+ const blob = await response.blob();
+ const url = window.URL.createObjectURL(blob);
Review Comment:
### Unbounded memory usage for large exports <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
Creating object URLs for potentially large export files without size validation can cause memory issues and browser crashes.
###### Why this matters
Large export files loaded entirely into memory as blobs can exhaust available RAM, especially on resource-constrained devices or when multiple exports are triggered simultaneously.
###### Suggested change ∙ *Feature Preview*
Add content-length validation before blob creation and consider streaming downloads for large files:
```typescript
const contentLength = response.headers.get('Content-Length');
const MAX_BLOB_SIZE = 100 * 1024 * 1024; // 100MB limit
if (contentLength && parseInt(contentLength, 10) > MAX_BLOB_SIZE) {
// Use streaming approach or direct link download
window.location.href = endpoint;
return;
}
const blob = await response.blob();
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4e60cc02-9860-4f69-93a3-92397676e6e8/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4e60cc02-9860-4f69-93a3-92397676e6e8?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4e60cc02-9860-4f69-93a3-92397676e6e8?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4e60cc02-9860-4f69-93a3-92397676e6e8?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/4e60cc02-9860-4f69-93a3-92397676e6e8)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:fcda2314-f400-47ef-bad8-1d3be86951eb -->
[](fcda2314-f400-47ef-bad8-1d3be86951eb)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387703103
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18390813558) for [18a325a](https://github.com/apache/superset/commit/18a325a)
• **Environment:** http://54.186.104.97:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387867386
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18392777817) for [4a94a4c](https://github.com/apache/superset/commit/4a94a4c)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on code in PR #35584:
URL: https://github.com/apache/superset/pull/35584#discussion_r2418782918
##########
superset-frontend/src/features/home/ChartTable.tsx:
##########
@@ -132,12 +132,17 @@ function ChartTable({
setLoaded(true);
}, [activeTab]);
- const handleBulkChartExport = (chartsToExport: Chart[]) => {
+ const handleBulkChartExport = async (chartsToExport: Chart[]) => {
const ids = chartsToExport.map(({ id }) => id);
- handleResourceExport('chart', ids, () => {
- setPreparingExport(false);
- });
setPreparingExport(true);
+ try {
+ await handleResourceExport('chart', ids, () => {
Review Comment:
Do we actually need to await this? If user tries to export multiple assets, they’ll be processed sequentially instead of in parallel.
This comment also applies to all other handleResourceExport calls in this PR
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35584:
URL: https://github.com/apache/superset/pull/35584#discussion_r2421705049
##########
superset-frontend/src/features/home/ChartTable.tsx:
##########
@@ -132,12 +132,17 @@ function ChartTable({
setLoaded(true);
}, [activeTab]);
- const handleBulkChartExport = (chartsToExport: Chart[]) => {
+ const handleBulkChartExport = async (chartsToExport: Chart[]) => {
const ids = chartsToExport.map(({ id }) => id);
- handleResourceExport('chart', ids, () => {
- setPreparingExport(false);
- });
setPreparingExport(true);
+ try {
+ await handleResourceExport('chart', ids, () => {
+ setPreparingExport(false);
+ });
+ } catch (error) {
Review Comment:
Do we have a test for this? If not we should validate that the toast message appears and the spinner clears so it's not in an infinite loading state.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387175995
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) deployed environment on [GHA](https://github.com/apache/superset/actions/runs/18386178625) for [da61031](https://github.com/apache/superset/commit/da61031)
• **Environment:** http://34.220.10.53:8080 (admin/admin)
• **Lifetime:** 48h auto-cleanup
• **Updates:** New commits create fresh environments automatically
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387421335
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18388518407) for [22afa04](https://github.com/apache/superset/commit/22afa04)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387840171
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18392486087) for [efe10ec](https://github.com/apache/superset/commit/efe10ec)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #35584:
URL: https://github.com/apache/superset/pull/35584#discussion_r2421705049
##########
superset-frontend/src/features/home/ChartTable.tsx:
##########
@@ -132,12 +132,17 @@ function ChartTable({
setLoaded(true);
}, [activeTab]);
- const handleBulkChartExport = (chartsToExport: Chart[]) => {
+ const handleBulkChartExport = async (chartsToExport: Chart[]) => {
const ids = chartsToExport.map(({ id }) => id);
- handleResourceExport('chart', ids, () => {
- setPreparingExport(false);
- });
setPreparingExport(true);
+ try {
+ await handleResourceExport('chart', ids, () => {
+ setPreparingExport(false);
+ });
+ } catch (error) {
Review Comment:
nit: Do we have a test for this? If not we should validate that the toast message appears and the spinner clears so it's not in an infinite loading state.
##########
superset-frontend/src/features/home/DashboardTable.tsx:
##########
@@ -118,12 +118,17 @@ function DashboardTable({
setLoaded(true);
}, [activeTab]);
- const handleBulkDashboardExport = (dashboardsToExport: Dashboard[]) => {
+ const handleBulkDashboardExport = async (dashboardsToExport: Dashboard[]) => {
const ids = dashboardsToExport.map(({ id }) => id);
- handleResourceExport('dashboard', ids, () => {
- setPreparingExport(false);
- });
setPreparingExport(true);
+ try {
+ await handleResourceExport('dashboard', ids, () => {
+ setPreparingExport(false);
+ });
+ } catch (error) {
Review Comment:
nit: Same question as above. Do we have a test that handles this part?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(export): replace iframe with fetch to avoid CSP frame-src violations [superset]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35584:
URL: https://github.com/apache/superset/pull/35584#issuecomment-3387675651
🎪 [Showtime](https://github.com/mistercrunch/superset-showtime) is building environment on [GHA](https://github.com/apache/superset/actions/runs/18390813558) for [18a325a](https://github.com/apache/superset/commit/18a325a)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org