BBCodePlus icon indicating copy to clipboard operation
BBCodePlus copied to clipboard

The source list for Content Security Policy directive 'frame-ancestors' contains an invalid source: ''none''

Open kuz30 opened this issue 7 years ago • 6 comments

Mantis 2.21.1 with latest BBCodePlus generates Google Chrome console error

The source list for Content Security Policy directive 'frame-ancestors' contains an invalid source: ''none''. It will be ignored. Note that 'none' has no effect unless it is the only expression in the source list.

due to response header: content-security-policy: ... frame-ancestors 'self' 'none'; ...

kuz30 avatar Jun 14 '19 14:06 kuz30

From what I have been able to gather, this is an unavoidable behavior. Furthermore, the BBCodePlus plugin is not the one adding the none source, which is the one with the warning. We are adding the self:

function csp_headers() {
 # relax csp when processing markitup.
 if ( (ON == plugin_config_get( 'process_markitup' )) && function_exists( 'http_csp_add' ) ) {
	http_csp_add( 'script-src', "'self' 'unsafe-inline' 'unsafe-eval' https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js" );
	http_csp_add( 'img-src', "*" );
	http_csp_add( 'frame-ancestors', "'self'" );
 }
}

I believe none is the default. Unfortunately (@atrol please correct me on this), http_csp_add does not remove CSP content, just appends it to the current CSP.

bkraul avatar Jun 14 '19 14:06 bkraul

That's true, 'none' is default for frame-ancestors in core/http_api.php. Looks like http_csp_add is not a best choise for plugin due to side-effects caused by console error.

kuz30 avatar Jun 14 '19 15:06 kuz30

Not sure there is much of an option. As I understand it, it is less safe to try to handle csp by sideloading, which is why http_csp_add was introduced. I'd defer to the mantisbt team on this. Also, this is not an error, but a warning. What side-effects are you experiencing as a result of this?

bkraul avatar Jun 14 '19 16:06 bkraul

Sorry, no time to have a deeper look at this.

The solution might be to introduce a special treatment in function http_csp_add if $p_type is frame-ancestors. In this case and If none is set, unset none.

atrol avatar Jun 14 '19 20:06 atrol

Closing this one as it doesn't really originate in BBCode plus, but at the mantis csp level. Will re-open when https_csp_add is worked on to address this.

bkraul avatar Aug 15 '19 17:08 bkraul

Proposed fix mantisbt/mantisbt#1554

dregad avatar Aug 28 '19 23:08 dregad