Skip to main content

Fixed: Framing '…' Violates the Following Content Security Policy Directive: "frame-ancestors …" in a Teams Dialog

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A Teams dialog that should have shown my agent's web page showed a grey area with a sad-page icon, and the browser's console said Framing '…' violates the following Content Security Policy directive: "frame-ancestors https://teams.microsoft.com https://*.teams.microsoft.com". The page allowed Teams' old addresses, but Teams on the web now runs at teams.cloud.microsoft.

What I Was Doing​

An agent built with the Microsoft 365 Agents SDK opens a Teams dialog that shows a page it serves itself, parking.html, through a dev tunnel. To stop other sites from showing its pages inside their own, the agent sends a Content-Security-Policy header with a frame-ancestors directive, set in Program.cs. I listed the Teams addresses I knew:

Program.cs (excerpt)
// Only Teams may show these pages inside its own page.
app.Use(async (context, next) =>
{
context.Response.Headers.ContentSecurityPolicy =
"frame-ancestors https://teams.microsoft.com https://*.teams.microsoft.com";
await next(context);
});

Then I opened the dialog in Teams on the web.

What I Expected​

A dialog titled Visitor parking, with two lines about where visitors park.

What I Got​

A grey page with a sad-page icon:

A Teams dialog titled Visitor parking from the app Dialog Page Demo, with a grey page area and a broken-page icon in the middle instead of the page.

Chrome's error page in the frame showed only that icon, and its text read cdzngt35-3980.inc1.devtunnels.ms refused to connect. The browser's console, which F12 opens in Chrome and Edge, said why:

Console
Framing 'https://cdzngt35-3980.inc1.devtunnels.ms/' violates the following Content Security Policy directive: "frame-ancestors https://teams.microsoft.com https://*.teams.microsoft.com". The request has been blocked.

What I Checked​

Whether the agent served the page. It did. The agent's request log showed the dialog request, then the page sent with 200:

Agent output
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 POST http://localhost:3980/api/messages - 200 - application/json;+charset=utf-8 27.1957ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:3980/parking.html - - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 GET http://localhost:3980/parking.html - 200 697 text/html 3.4391ms

So the browser received the page, with its header, and then refused to show it.

What the message means. frame-ancestors lists the pages allowed to show this page in a frame. The message quotes my own list back, so the page that framed it wasn't on the list.

Where Teams on the web runs. The browser's address bar showed https://teams.cloud.microsoft/. That isn't teams.microsoft.com, and it isn't under teams.microsoft.com either.

What Microsoft's documentation says. The requirements for tabs list the frame-ancestors values for each Microsoft 365 host. The first row is new:

Microsoft 365 app hostframe-ancestor permission
All hosts (New)*.cloud.microsoft
Teamsteams.microsoft.com, *.teams.microsoft.com

The same page warns: Microsoft's cloud services, including web versions of Teams, Outlook, and Microsoft 365 domains, are migrating to the *.cloud.microsoft domain. It asks apps to update the frame-ancestors directive to include the *.cloud.microsoft domain, and to retain the existing frame-ancestors values in your CSP headers for backward compatibility.

Why It Happens​

Teams on the web moved to teams.cloud.microsoft, and my frame-ancestors list only had Teams' older addresses. The browser checks the list against the pages that frame the dialog's page. teams.cloud.microsoft didn't match, so the browser blocked the frame and showed its own error page instead.

The Fix​

Add https://*.cloud.microsoft to the list, and keep the values that were already there:

Program.cs (excerpt)
// Only Teams may show these pages inside its own page.
app.Use(async (context, next) =>
{
context.Response.Headers.ContentSecurityPolicy =
"frame-ancestors https://teams.microsoft.com https://*.teams.microsoft.com https://*.cloud.microsoft";
await next(context);
});
  • https://*.cloud.microsoft covers teams.cloud.microsoft and the other Microsoft 365 apps that have moved to that domain.
  • The two older values stay, as Microsoft's page asks, for backward compatibility while the move goes on.

Stop the agent with Ctrl+C and start it again with dotnet run, so it sends the new header. How to Add a Content-Security-Policy Header in ASP.NET Core (C#) explains this middleware and how to check the header with curl -I.

If your app also runs in Outlook or the Microsoft 365 app, the same table on Microsoft's page lists their values too.

After the Fix​

The same dialog showed the page:

The Visitor parking dialog showing the page: Visitor parking is on level -1, bays 1 to 12., and Tell the front desk your car's number plate when you arrive.

The console had no frame-ancestors message this time.

Common Mistakes​

MistakeWhat happensDo this instead
A frame-ancestors list with only teams.microsoft.com and *.teams.microsoft.comTeams on the web, at teams.cloud.microsoft, is blockedAdd https://*.cloud.microsoft
Replacing the old values with *.cloud.microsoftMicrosoft asks apps to keep them during the moveKeep them and add the new one
Editing the header without restarting the agentThe old header is still sentRestart the agent

Troubleshooting​

SymptomLikely causeFix
A grey dialog with a sad-page icon, and violates the following Content Security Policy directive: "frame-ancestors …" in the consoleThe page's frame-ancestors doesn't include the address Teams runs onAdd https://*.cloud.microsoft
The page opens in its own browser tab but not in Teamsframe-ancestors applies only when another page shows yours in a frameCheck the console of the Teams tab, not the page's own tab
Still blocked after the changeThe agent is still running the old codeStop it and run dotnet run again

FAQ​

Do I need a frame-ancestors directive at all?​

Without one, any site can show your page inside its own. With one, only the hosts you list can. Microsoft's requirements for tabs ask you to set it so that Teams and the other Microsoft 365 hosts are allowed.

Why does the console show the tunnel's address and not my page's?​

Chrome names the framed page's origin, its scheme, host and port, rather than its full address, so the message shows https://cdzngt35-3980.inc1.devtunnels.ms/ for parking.html. The directive quoted after it is the one your page sent.

Conclusion​

Framing '…' violates the following Content Security Policy directive: "frame-ancestors …" in a Teams dialog means your page's frame-ancestors list doesn't include the address Teams runs on. Teams on the web is at teams.cloud.microsoft, so add https://*.cloud.microsoft and keep https://teams.microsoft.com https://*.teams.microsoft.com, as Microsoft's requirements for tabs ask.

Additional Resources​