Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [content-security-policy]

Content Security Policy is a mechanism for mitigating attacks against web applications.

1
vote
1answer
95 views

Trying to understand Content-Security-Policy: Why do some sites (e.g Google) use a “nonce”, but also allow all inline scripts and use of eval()?

Here is an example of the CSP of accounts.google.com: content-security-policy: script-src 'nonce-DanEwkxkS1rktq35Z1hVcg' 'unsafe-inline' 'unsafe-eval';object-src 'none';base-uri 'self';report-uri /...
1
vote
1answer
74 views

Content Security Policy: postMessage into foreign iframe

Assume we have a webpage with sensitive data. The page uses a marketing partner advertisingpartner.com which collects data via third-party cookies in a foreign iframe. We have applied a relatively ...
1
vote
0answers
70 views

How to whitelist an iframe and script of some other source embeded/ called by an iframe that is whitelisted in the CSP?

For example I am having an iframe with src https://iframe1.com which is listed in my content security policy. If the whitelisted iframe calls some iframe from another source like https://iframe2.com, ...
1
vote
1answer
81 views

Does CSP block javascript in <a href> tags?

I recently discovered that its possible to run javascript from an <a> tag like this <a href="javascript:alert('test')"> and this gets run on the current page when clicked. It also seems ...
0
votes
2answers
413 views

Prevent javascript cross-origin redirect by window.location.href

Following this question, is there a way to prevent this code from redirecting users to domains not whitelisted? const form = document.getElementsByTagName('form')[0]; form.addEventListener('submit', ...
24
votes
4answers
7k views

Can I trust public code versioning platforms when building a social platform?

We are developing a kind of social platform. It starts as a closed beta for a limited number of users, but the goal is to reach millions of subscriptions. We are currently limited on resources, both ...
1
vote
1answer
31 views

Are Content-Security-Policy nonces designed for production use, or as a stop-gap when implementing a CSP?

Some websites use Content-Security-Policy nonces in order to include inline styling and script in their webpages. Is the CSP nonce feature designed to be used for production use, or is it simply ...
0
votes
1answer
210 views

CSP - Unsafe-inline or unsafe-eval for specific domain is allowed or not

Following is a CSP policy, for example derived sample response headers. The implementation below allows white-listed domains only in "script-src" directive but the 'unsafe-inline' and 'unsafe-eval' ...
0
votes
1answer
84 views

Prevent javascript cross-origin write

Let's assume an attacker manages to inject this script in a login page: const form = document.getElementsByTagName('form')[0]; form.addEventListener('submit', stealCredentials); function ...
2
votes
1answer
41 views

is there a low-overhead way to log every new file created on a Linux host?

I know about inotify but am concerned it would use too many resources. Is there a better way to monitor a fairly static system (like a web host) for new and unexpected files being created?
3
votes
2answers
174 views

Does allowing unsafe-inline script defeat the purpose of CSP?

I am reviewing the Content-Security-Policy headers set in one of our webservers and I see this is how it is set (where 'example.com' is our trusted website). Content-Security-Policy: "default-src '...
2
votes
2answers
188 views

Content Security Policy Header not stopping attack

I created a simple test web application to test the use of the content security policy header. I included a vulnerability in my test app, such that submitting a basic XSS payload with script tags ...
5
votes
3answers
256 views

How to safely allow scripts but preventing XSS?

We are trying to find the best way to allow JavaScript in a web application while being safe against XSS. Site admins have the privilege to insert JavaScript to control the site templates, and ...
2
votes
0answers
86 views

What are the dangers of “style-src: 'unsafe-inline'”? [duplicate]

This is a common sight in content security policies: style-src 'unsafe-inline' I know that this "UI redressing attacks" that can be use for phishing or just defamation. But are there other threats ...
1
vote
0answers
140 views

Data image with CSP

I am trying to get an image that is within JavaScript to work with our CSP. I have read that using data: (even in img-src) is an XSS risk so I'm trying to avoid that. Because it is called from within ...
2
votes
1answer
63 views

CSP to report HTTP resources?

I would like to start introducing a CSP on a site. I would like to start by adding a report only CSP and only reporting on mixed content, for example when an images is loading from HTTP instead of ...
3
votes
1answer
245 views

How do I control multiply-nested embedding of my iframe?

Domain example1.com embeds my iframe. Domain example2.com embeds an iframe served from example1.com. I would set X-Frame-Options: ALLOW FROM *.example1.com as well as Content-Security-Policy with ...
4
votes
1answer
1k views

What's the alternative of content security policy (CSP) header in Internet Explorer IE?

As mentioned in the Content Security Policy documentation & from the "supported browsers" page on the CSP site, CSP is not supported in Internet Explorer. So, if we want to support CSP in our ...
1
vote
1answer
67 views

Do we need to add CSP to all web pages in a web application?

We have a multi-page web application. I understand that ideally CSP should be set for text/html responses only. Is it enough to add content security policy (CSP) header to the login page or should I ...
1
vote
2answers
298 views

What attacks does Content Security Policy base-uri protect against?

I have read up on base-uri and the HTML base tag, but what exactly is the base-uri CSP is meant to protect against?
1
vote
0answers
517 views

Is allowing blob: in Content-Security-Policy a risk?

Recently, I've set Content-Security-Policy headers for my web application. I've tried to be as strict as possible. What strikes me most is the fact that I had to allow blob: for connect-src and img-...
0
votes
2answers
87 views

Best way to encrypt user data stored in xml?

First of all I am not very familiar with the world of encryption so please be nice. I have got a data that should store in an xml using NetDataContractSerializer. This xml file gets the size of from ...
2
votes
0answers
230 views

"Protection Mechanism Failure (CWE ID 693)

After security scan, we are seeing the Protection Mechanism Failure (CWE ID 693) issue in our application. Our current header is set as mentioned below- Server: Apache X-Frame-Options: SAMEORIGIN ...
1
vote
0answers
36 views

How to protect the control environment of my web application? [closed]

I am developing a web application and want to do its setup and control using my personal notebook. However, the following topics concern me: 1) Enter the platform (includes the login in the control ...
15
votes
1answer
541 views

Is it safe to send Content-Security-Policy header for text/html content-type only?

Is it safe to send Content-Security-Policy for dynamically generated pages with text/html and other hypertext content-types only or do I need to send this header for all files including static assets -...
2
votes
1answer
350 views

Content-Security-Policy suspicious entries in the log

I've set up Content-Security-Policy-Report-Only header, and am in report-uri getting relatively high number (several hundred per month) of failed requests on img-src for suspicious URLs: https://...
0
votes
0answers
37 views

WebWorker Hash-Source CSP importScripts

I have been trying to move my site to hash-source CSP instead of host-source CSP to verify integrity of files distributed by a CDN. I have a WebWorker running in the background, which imports a few ...
0
votes
1answer
321 views

CSP header default-src: data:

I am testing CSP header implementation. The implemented header value is: Content-Security-Policy: default-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-...
0
votes
0answers
200 views

Single Page Application and CSRF Token generated every time

I need to use a Single Page Application (React, Ember, Angular, I don't care) with Rails CSRF protection mechanism. I'm wondering if I need to create a token evey time in the ApplicationController ...
2
votes
1answer
378 views

SRI for CSP - how do I get the hash for inline code?

I have been messing about with website design for years, but I am no expert - more of a hardware junkie. CSP is fascinating for me now that I am starting to branch out into web development. I was ...
5
votes
1answer
227 views

Can BeEF hooking be stopped with Content Security Policies

I know that using strict values for default-src and scripts-src are a popular way to prevent (or at least limit the impact) of XSS attacks. But I was just wondering it CSPs can be used to stop ...
4
votes
2answers
423 views

What does the CSP require-sri-for directive protect against?

According to Mozilla: The HTTP Content-Security-Policy require-sri-for directive instructs the client to require the use of Subresource Integrity for scripts or styles on the page. I fail to see ...
4
votes
3answers
3k views

Why does Chrome tell me that the CSP 'require-sri-for' directive is implemented behind a flag which is currently disabled?

In my Content Security Policy I have included require-sri-for script. However, in the Chrome console I get a notice (not an error, just info): The Content-Security-Policy directive 'require-sri-for'...
2
votes
1answer
373 views

Does Chrome respect the X-DNS-Prefetch-Control header?

If my web page returns X-DNS-Prefetch-Control=off, will Chrome do DNS prefetch for links like these?: <link rel="dns-prefetch" href="http://www.spreadfirefox.com/"> I know Firefox and Chromium ...
0
votes
3answers
126 views

Why doesn't CSP block JS from modifying an element's style?

You can use Content Security Policy to disallow style attributes, but you can just get around this just by using javascript to modify an element's style. Isn't this a security hole or am I missing ...
5
votes
1answer
717 views

XSS vulnerability with strict CSP

The article I’m harvesting credit card numbers and passwords from your site. Here’s how. describes the phases of a theoretical attack where an attacker can bypass a strict CSP and exfiltrate sensitive ...
2
votes
1answer
70 views

Should I allow http script sources in my CSP, or enforce https only?

I'm currently trying to implement a third-party widget into my website. That widget attempts to load some scripts over http, which is currently disallowed by my content security policy. I'm concerned ...
4
votes
1answer
166 views

Poor result on securityheaders.io for google.com

I have just tested google on securityheaders.io and the result was D. Google is actually not setting following security headers Content-Security-Policy X-Content-Type-Options Referrer-Policy I ...
0
votes
1answer
54 views

How to perform attack that requires me to set a CSP on a site I do not control?

I am reading this blog post about an vulnerability on uber.com. It says that you will have to set a content security policy: We’ll set our policy to only allow requests to partners.uber.com, which ...
3
votes
1answer
68 views

Is it possible to specify a content security policy in browsers?

Normally, content security policies are sent in the response headers by the server to the client browser telling it what is and is not acceptable to load on the site. Is there a way to do this in ...
0
votes
1answer
598 views

CSP report-uri does not work

I'm using the following PHP script to test CSP policy, <?php header("Content-Security-Policy: default-src https:; report-uri /report.php"); header("Content-Security-Policy: default-src 'self'...
2
votes
2answers
481 views

CSP: upgrade-insecure-requests - what happens with https-incompatible ressources?

I have two questions regarding the CSP directive upgrade-insecure-requests which I couldn't answer myself by reading the specification. What happens to ressources which can't be upgraded to https (e....
5
votes
1answer
805 views

Content-Security-Policy: Getting weird reports with frame-ancestors 'self'

Right now, I maintain the Content-Security-Policy for https://www.lidl.de, which is: Content-Security-Policy: frame-ancestors 'self'; block-all-mixed-content; report-uri https://lidlcsp.report-uri.io/...
0
votes
2answers
539 views

What vulnerability do inline javascript and event handlers expose? [duplicate]

I'm trying to understand why certain CSPs block inline javascript. Is the concern that a user will be able to insert javascript that will then be served to other users? If so, isn't this an issue with ...
1
vote
0answers
522 views

HTTP security headers for native and webview based mobile applications

OWASP Security Headers Project recommends the following security headers for web applications. Out of the following which headers are relevant to mobile applications? HTTP Strict Transport Security (...
2
votes
1answer
339 views

Does an Embedded Content Security Policy (CSP) Enforcement ruin a “regular” CSP?

I recently read a W3C Working Draft about the Embedded Enforcement of a Content Security Policy (CSP). This document defines a mechanism by which a web page can embed a nested browsing context if ...
1
vote
1answer
1k views

Bypass Content Security Policy: Using Form tag

This article talks about bypassing CSP using Form tags. Edit: As suggested, details has to be provided in case the external link stops working. So here are the details: There is content-security-...
1
vote
1answer
347 views

Using Content Security Policy in AMP-HTML pages?

I have a site built with AMP. I tried to use Content-Security-Policy: script-src 'self', but all styles and designs didn't show properly since they are loaded from cdn.ampproject.org. Google, in their ...
1
vote
0answers
35 views

Getting the following error: default-src 'none' [duplicate]

I'm making a game with a library called Processing.js. This library has two built in functions that allow me to save and retrieve information from a .txt file. But when I tried to use this functions ...
3
votes
1answer
526 views

CSP base-uri directive on “View page source” on

I am in the process of implementing a CSP header for a webapp, with the goal of reducing possible XSS attacks. See CSP for an overview of CSP. I provided the base-uri directive as 'self' and this ...