Access-Control-Allow-Credentials header


目录

The HTTP Access-Control-Allow-Credentials response header tells browsers whether the server allows credentials to be included in cross-origin HTTP requests.

Credentials include cookies, Transport Layer Security (TLS) client certificates, or authentication headers containing a username and password. By default, these credentials are not sent in cross-origin requests, and doing so can make a site vulnerable to Cross-Site Request Forgery (CSRF) attacks.

A client can ask for credentials to be included in cross-site requests in several ways:

When credentials are included:

Header type [Response header](https://developer.mozilla.org/en-US/docs/Glossary/Response%20header)

Syntax

Access-Control-Allow-Credentials: true

Directives

Examples

Allow credentials:

Access-Control-Allow-Credentials: true

Using fetch() with credentials:

fetch(url, {
  credentials: "include",
});

Using XMLHttpRequest with credentials:

const xhr = new XMLHttpRequest();
xhr.open("GET", "http://example.com/", true);
xhr.withCredentials = true;
xhr.send(null);

Specifications

Browser compatibility

See also


版本号 #3
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 cocobook-sync 更新于 2026-11-04 17:35:35 UTC