Skip to content

SPFx and Content Security Policy produce errors on each script source if server relative URL used #10369

@vlad-nvs

Description

@vlad-nvs

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK, or API is this about?

💥 SharePoint Framework

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • SPFx version 1.18.2
  • Node.js version 18.17.1

Describe the bug/error

Content Security Policy (CSP) has now been introduced for SharePoint Online.
A new tab is available in the SharePoint Admin Center under Advanced → Script sources.

Image

It contains all script URLs from the SPFx solutions, and everything seems to work well. However, when a server relative URL is used (scripts are on the same Tenant), the browser console shows errors such as:

Image

The source list for the Content Security Policy directive 'script-src' contains an invalid source: '/sites/..../.../..../'. It will be ignored.

For now, these are just console errors, and everything appears to be working correctly. However, if there are multiple SPFx solutions, it becomes difficult to identify real issues.

Furthermore, it identifies errors for Script sources that are hosted on different sites.

As far as I know, it is allowed to use relative URLs in SPFx, e.g., in cdnBasePath, and it is even possible to add such URLs to Script sources via the SharePoint Admin Center UI.

Can someone explain why these errors occur for relative URLs in script sources, and whether using relative URLs in SPFx solutions might have any impact in the future?

Steps to reproduce

  1. Create SPFx solution
  2. Use a relative URL for cdnBasePath
  3. Upload SPFx to App Catalog and install on any site

Expected behavior

I think server relative URLs should work properly with the Content Security Policy feature since it's allowed to use them in a SPFx solution from the beginning (and everything works), and it should not produce errors for such script sources

Metadata

Metadata

Assignees

Labels

sharepoint-developer-supportsharepoint-developer-supporttype:bug-suspectedSuspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.type:uservoice-requestEnhancements & feature requests should be posted: http://aka.ms/sp-dev-uservoice

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions