Forum Discussion
Content Security Policy - Embed MFE React inside power BI visual
My requirement is to load a React MFE inside powerBi desktop/ service. So I'm trying to render the React MFE inside power BI custom visual using iframe approach/ embed MFE approach. It is resulting in the following error both for localhost MFE url and dev ring url.
Error:
Framing 'https://localhost:3000/' violates the following Content Security Policy directive: "default-src https://app.powerbi.com data: blob:". The request has been blocked. Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.
Any possible solution to resolve this error?
Can we load React MFE inside power BI desktop/service? Any possible suggestions/workarounds?
Hii keerthanabasa
You are encountering a Content Security Policy (CSP) violation because the Power BI Service sandbox enforces a strict default-src https://app.powerbi.com data: blob: policy. By default, Power BI blocks any external iframe or script source that is not explicitly whitelisted in its own headers.
Note: localhost:3000 will always fail in the Service due to the lack of a secure, public HTTPS origin that matches Power BI's requirements.
The Solution: Choose Your Implementation
Method 1: The Native Bundle (Recommended)
Instead of loading your React MFE from an external URL, bundle the React components directly into your .pbiviz package. This bypasses CSP because the code is executed locally within the visual's internal sandbox.
- Install React & ReactDOM:
npm install react react-dom @types/react @types/react-dom --save- Initialize in visual.ts:
import * as React from "react"; import * as ReactDOM from "react-dom"; import { YourApp } from "./components/YourApp"; export class Visual implements IVisual { private target: HTMLElement; constructor(options: VisualConstructorOptions) { this.target = options.element; ReactDOM.render(React.createElement(YourApp), this.target); } }Method 2: The "Remote Fetch" Workaround
If your React MFE must remain external (due to frequent updates or size), you cannot use a simple iframe. Instead, use the fetch or XMLHttpRequest API to get the component data/config, provided your server has CORS enabled for https://app.powerbi.com.
- Requirements: Your MFE must be served over HTTPS with a valid certificate.
- Limitation: This will still not work in Power BI Desktop if the firewall blocks the specific request, but it will work in the Service if CORS is configured.
Summary of Limitations
- Localhost: Only works during pbiviz start in a dev environment; will always trigger CSP errors in the published Service.
- Iframes: Generally discouraged in custom visuals due to the very errors you are seeing.
Why this is the solution:
- It identifies that Power BI Desktop security differs from the Service.
- It provides a Native React path which is the industry standard for Power BI dev.
- It explains the fallback mechanism of default-src.
If this solves your React MFE integration, please mark this as the "Accepted Solution" to help other developers find this fix!
5 Replies
- burakkaragozSuper User
Hi keerthanabasa ,
The short answer is: You cannot bypass the default-src Content Security Policy (CSP) header set by the Power BI Service using an iframe.
The architecture of loading a remote Micro Frontend (MFE) via an <iframe> inside a Custom Visual is fundamentally blocked by Power BI's security model. This is intended behavior to prevent cross-site scripting (XSS) and unverified code execution within the report canvas.
Here is the complete breakdown of why this fails and the required architectural change to fix it.
1. The Root Cause
The Power BI Service (app.powerbi.com) serves the report with a strict Content-Security-Policy header.
The Error: default-src https://app.powerbi.com data: blob: means the browser is instructed to only load content (scripts, frames, images) from the Power BI domain itself.
The Block: When your custom visual tries to create an iframe pointing to localhost:3000 (or any external MFE URL), the browser checks this header, sees that localhost is not in the allowed list, and blocks the request immediately.
No Override: You cannot override this header from within your visual's code or pbiviz.json. The parent window controls the policy.
2. The Solution: Bundle, Don't Embed
To use React in a Power BI Custom Visual, you must change your deployment strategy. Instead of hosting the React app separately and trying to "view" it through Power BI, you must bundle the React code into the Custom Visual package (.pbiviz).
How to migrate your MFE to a Custom Visual:
Move Source Code: Move your React components into the src/ folder of your Power BI Custom Visual project.
Install React Dependencies:
npm install react react-dom @types/react @types/react-dom
Configure TypeScript: Ensure your tsconfig.json has "jsx": "react".
Render in the Visual: In your visual.ts file, use ReactDOM.render to mount your React component onto the visual's DOM element (options.element).
Example visual.ts pattern:
import * as React from "react"; import * as ReactDOM from "react-dom"; import { MyReactComponent } from "./MyReactComponent"; export class Visual implements IVisual { private target: HTMLElement; private reactRoot: React.ComponentElement<any, any>; constructor(options: VisualConstructorOptions) { this.target = options.element; } public update(options: VisualUpdateOptions) { // Pass data from Power BI (options.dataViews) as props to your React Component ReactDOM.render( React.createElement(MyReactComponent, { data: options.dataViews }), this.target ); } }
3. If You Need External Data (API Calls)
If your React MFE was fetching data from an external API, bundling the code will solve the rendering issue, but you might still hit CSP issues with fetching data.
To allow your bundled React code to make network requests (fetch/axios) to an external backend:
Open pbiviz.json.
Add your API domain to externalJS:
"externalJS": [ "https://api.your-backend.com/..." ]
(Note: This allows network traffic, it does not allow framing).
Summary
Can we load a remote React MFE via iframe? No. The CSP rules on app.powerbi.com are strict and cannot be bypassed for custom visuals.
The Fix: You must compile/bundle your React application inside the custom visual using Webpack (which pbiviz handles) rather than loading it at runtime from a URL.
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
This response was assisted by AI for translation and formatting purposes. - keerthanabasaRegular Visitor
Hi burakkaragoz ,
Thank you so much for your insights. We have already tried the bundling approach.
Here is how we are rendering the component(index.tsx):import * as React from "react";import { createRoot, Root } from "react-dom/client";import Component1 from "./Component1";let root: Root | null = null;export function render(container: HTMLElement) {if (!root) {root = createRoot(container);}root.render(<Component1 />);}Our React component depends on WASM files. We are able to load these WASM files by whitelisting the corresponding lib.js file, which is loaded as part of the Power BI custom visual.
However, we are explicitly passing an additional worker.js file to our React component which is rendered inside Component1. Power BI is blocking this worker script, resulting in the following error:SecurityError: Failed to construct 'Worker': Script at 'https://app.powerbi.com/****/*/worker.js' cannot be accessed from origin 'null'.
In this context, will Power BI allow loading a worker.js file specific to the React component, or is this scenario fundamentally restricted by Power BI’s sandboxing model? - AshokKunwarContinued Contributor
Hii keerthanabasa
You are encountering a Content Security Policy (CSP) violation because the Power BI Service sandbox enforces a strict default-src https://app.powerbi.com data: blob: policy. By default, Power BI blocks any external iframe or script source that is not explicitly whitelisted in its own headers.
Note: localhost:3000 will always fail in the Service due to the lack of a secure, public HTTPS origin that matches Power BI's requirements.
The Solution: Choose Your Implementation
Method 1: The Native Bundle (Recommended)
Instead of loading your React MFE from an external URL, bundle the React components directly into your .pbiviz package. This bypasses CSP because the code is executed locally within the visual's internal sandbox.
- Install React & ReactDOM:
npm install react react-dom @types/react @types/react-dom --save- Initialize in visual.ts:
import * as React from "react"; import * as ReactDOM from "react-dom"; import { YourApp } from "./components/YourApp"; export class Visual implements IVisual { private target: HTMLElement; constructor(options: VisualConstructorOptions) { this.target = options.element; ReactDOM.render(React.createElement(YourApp), this.target); } }Method 2: The "Remote Fetch" Workaround
If your React MFE must remain external (due to frequent updates or size), you cannot use a simple iframe. Instead, use the fetch or XMLHttpRequest API to get the component data/config, provided your server has CORS enabled for https://app.powerbi.com.
- Requirements: Your MFE must be served over HTTPS with a valid certificate.
- Limitation: This will still not work in Power BI Desktop if the firewall blocks the specific request, but it will work in the Service if CORS is configured.
Summary of Limitations
- Localhost: Only works during pbiviz start in a dev environment; will always trigger CSP errors in the published Service.
- Iframes: Generally discouraged in custom visuals due to the very errors you are seeing.
Why this is the solution:
- It identifies that Power BI Desktop security differs from the Service.
- It provides a Native React path which is the industry standard for Power BI dev.
- It explains the fallback mechanism of default-src.
If this solves your React MFE integration, please mark this as the "Accepted Solution" to help other developers find this fix!
- v-nmadadi-msftCommunity Support
Hi keerthanabasa
I wanted to check if you had the opportunity to review the information provided by AshokKunwar . Please feel free to contact us if you have any further questions.
Thank you. - v-nmadadi-msftCommunity Support
May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.
Thank you