files/en-us/web/http/reference/headers/content-security-policy/connect-src/index.md
The HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP)
connect-src directive restricts the URLs which can be
loaded using script interfaces. The following APIs are controlled by this directive:
ping attribute in {{htmlelement("a")}} elements<table class="properties"> <tbody> <tr> <th scope="row">CSP version</th> <td>1</td> </tr> <tr> <th scope="row">Directive type</th> <td>{{Glossary("Fetch directive")}}</td> </tr> <tr> <th scope="row">{{CSP("default-src")}} fallback</th> <td> Yes. If this directive is absent, the user agent will look for the <code>default-src</code> directive. </td> </tr> </tbody> </table>[!NOTE]
connect-src 'self'does not resolve to websocket schemes in all browsers, more info in this issue.
Content-Security-Policy: connect-src 'none';
Content-Security-Policy: connect-src <source-expression-list>;
This directive may have one of the following values:
'none'
<source-expression-list>
Given this CSP header:
Content-Security-Policy: connect-src https://example.com/
The following connections are blocked and won't load:
<a ping="https://not-example.com" href="/">Link</a>
<script>
const response = fetch("https://not-example.com/");
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://not-example.com/");
xhr.send();
const ws = new WebSocket("wss://not-example.com/");
const es = new EventSource("https://not-example.com/");
navigator.sendBeacon("https://not-example.com/", {
/* … */
});
</script>
{{Specifications}}
{{Compat}}
ping