Setting up CSP for FaceTec Browser SDK

Learn how to setup the Content Security Policy (CSP) for the FaceTec Browser SDK.


Loading Browser SDK Locally

Example Setting

<meta http-equiv="Content-Security-Policy" content="
    default-src 'none';
    object-src 'none';
    script-src 'self' 'unsafe-eval' http://localhost:7777 https://YOUR_CODE_SERVER_URL;
    script-src-elem 'self';
    connect-src 'self' https://YOUR_API_SERVER_URL;
    img-src 'self' data:;
    style-src 'self' 'unsafe-inline';
    font-src 'none';
    media-src 'self' data:;
">
Important Note: The above example shows the minimum recommended settings for loading the FaceTec Browser SDK locally. There are numerous combinations of derivatives and derivative settings that can be used when configuring the CSP settings. As such, these settings may need to be modified in order to best suit the needs of your Users and your App.

Content Settings Reference

default-src 'none':

URLs cannot be loaded as a default source for other CSP fetch directives. This setting ensures that the CSP fetch directives only load URLs that have been directly specified.

default-src - "[S]erves as a fallback for the other CSP fetch directives" (definition from MDN Web Docs)

'none' - "Refers to the empty set; that is, no urls match." (definition from MDN Web Docs)

object-src 'none':

URLs cannot be loaded for the <object> and <embed> elements. This directive uses 'none' since the <object> and <embed> elements are not used by the FaceTec Browser SDK.

object-src - "[S]pecifies valid sources for the <object> and <embed> elements." (definition from MDN Web Docs)

'none' - "Refers to the empty set; that is, no urls match." (definition from MDN Web Docs)

script-src 'self' 'unsafe-eval' http://localhost:7777 https://YOUR_CODE_SERVER_URL:

The only URLs that can be loaded and used for Javascript are the document's origin URL, http://localhost:7777, and https://YOUR_CODE_SERVER_URL. The FaceTec Browser SDK requires 'unsafe-eval' due to an open Chromium bug.

'script-src' - "[S]pecifies valid sources for JavaScript. This includes not only URLs loaded directly into <script> elements, but also things like inline script event handlers (onclick) and XSLT stylesheets which can trigger script execution." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

unsafe-eval' - "Allows the use of eval() and other unsafe methods for creating code from strings." (definition from MDN Web Docs)

http://localhost:7777 - Adds any URL loaded from port 7777*. (for development purposes)

*This port should be the one you use for web app development. It does not have to be 7777.

https://YOUR_CODE_SERVER_URL - Adds the URL for your code server.

script-src-elem 'self':

The only URL that can be loaded and used for Javascript <script> elements is the document's origin URL.

'script-src-elem' - "[S]pecifies valid sources for JavaScript <script> elements." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number."(definition from MDN Web Docs)

connect-src 'self' https://YOUR_API_SERVER_URL:

Allows 'self' and https://YOUR_API_SERVER_URL to be loaded with certain script interfaces, such as fetch() and an XMLHttpRequest.

Important Note: You should add any URL here that your Web App uses with fetch() or an XMLHttpRequest.

connect-src - "[R]estricts the URLs which can be loaded using script interfaces." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

https://YOUR_API_SERVER_URL - Adds the URL* for your API server for session-token and biometric calls. This allows access to additional URLs (besides the one referenced by 'self').

* This URL may or may not be the same as your code server.

img-src 'self' data:

Only allows images and favicons to be loaded from 'self' (including the data: portions of 'self').

img-src - "[S]pecifies valid sources of images and favicons." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

data: - "Allows data: URLs to be used as a content source." (definition from MDN Web Docs)

style-src 'self' 'unsafe-inline':

Only allows stylesheets to be loaded from 'self'. The FaceTec Browser SDK requires 'unsafe-inline' to dynamically load styles.

style-src - "[S]pecifies valid sources for stylesheets." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

‘unsafe-inline’ - "Allows the use of inline resources, such as inline <script> elements, javascript: URLs, inline event handlers, and inline <style> elements." (definition from MDN Web Docs)

font-src 'none':

Fonts cannot be loaded with @font-face. This directive uses 'none' since the FaceTec Browser SDK does not use @font-face.

font-src - "[S]pecifies valid sources for fonts loaded using @font-face." (definition from MDN Web Docs)

'none' - "Refers to the empty set; that is, no URL s match." (definition from MDN Web Docs)

media-src 'self' data:

Only allows media using the <audio> and <video> elements to be loaded from 'self' (including the data: portions of 'self').

media-src - "[S]pecifies valid sources for loading media using the <audio> and <video> elements." (definition from MDN Web Docs)

data - "Allows data: URLs to be used as a content source." (definition from MDN Web Docs)


Loading Browser SDK from CDN

Example Setting

<meta http-equiv="Content-Security-Policy" content="
    default-src 'none';
    object-src 'none';
    script-src 'self' 'unsafe-eval' http://localhost:7777;
    script-src-elem 'self' 'unsafe-inline' blob: https://YOUR_CDN_BASE_URL;
    connect-src 'self' https://YOUR_API_SERVER_URL https://YOUR_CDN_BASE_URL;
    img-src 'self' data: https://YOUR_CDN_BASE_URL;
    style-src 'self' 'unsafe-inline';
    font-src 'none';
    media-src 'self' data: https://YOUR_CDN_BASE_URL;
    worker-src 'self' blob:;
">
Important Note: The above example shows the minimum recommended settings for loading the FaceTec Browser SDK from a CDN. There are numerous combinations of derivatives and derivative settings that can be used when configuring the CSP settings. As such, these settings may need to be modified in order to best suit the needs of your Users and your App.

Content Settings Reference

Important Note: Only the directives that differ from those in Loading the Browser SDK Locally are described below.

script-src 'self' 'unsafe-eval' http://localhost:7777:

https://YOUR_CODE_SERVER_URL has been removed since the FaceTec Browser SDK is no longer loaded from there.

'script-src' - "[S]pecifies valid sources for JavaScript. This includes not only URLs loaded directly into <script> elements, but also things like inline script event handlers (onclick) and XSLT stylesheets which can trigger script execution." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

unsafe-eval' - "Allows the use of eval() and other unsafe methods for creating code from strings." (definition from MDN Web Docs)

http://localhost:7777 - Adds any URL loaded from port 7777*. (for development purposes)

* This port should be the one you use for web app development. It does not have to be 7777.

script-src-elem 'self' 'unsafe-inline' blob: https://YOUR_CDN_BASE_URL:

blob: is used to allow WebAssembly to load from the CDN. https://YOUR_CDN_BASE_URL is specified since the FaceTec Browser SDK is being loaded from the CDN.

'script-src-elem' - "[S]pecifies valid sources for JavaScript <script> elements." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

‘unsafe-inline’ - "Allows the use of inline resources, such as inline <script> elements, javascript: URLs, inline event handlers, and inline <style> elements." (definition from MDN Web Docs)

blob: - "Allows blob: URIs to be used as a content source." (definition from MDN Web Docs)

https://YOUR_CDN_BASE_URL - Adds any URL loaded from your CDN.

connect-src 'self' https://YOUR_API_SERVER_URL https://YOUR_CDN_BASE_URL:

https://YOUR_CDN_BASE_URL is specified since the FaceTec Browser SDK is being loaded from the CDN.

Important Note: You should add any URL here that your Web App uses with fetch() or an XMLHttpRequest.

connect-src - "[R]estricts the URLs which can be loaded using script interfaces." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

https://YOUR_API_SERVER_URL - Adds the URL for your API server for session-token and biometric calls.

https://YOUR_CDN_BASE_URL - Adds the URL for your CDN.

img-src 'self' data: https://YOUR_CDN_BASE_URL:

https://YOUR_CDN_BASE_URL has been added to allow images to be loaded from the CDN.

img-src - "[S]pecifies valid sources of images and favicons." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

data: - "Allows data: URLs to be used as a content source." (definition from MDN Web Docs)

https://YOUR_CDN_BASE_URL - Allows images to be loaded from the CDN.

media-src 'self' data: https://YOUR_CDN_BASE_URL:

https://YOUR_CDN_BASE_URL has been added to allow media to be loaded from the CDN.

media-src - "[S]pecifies valid sources for loading media using the <audio> and <video> elements." (definition from MDN Web Docs)

data - "Allows data: URLs to be used as a content source." (definition from MDN Web Docs)

https://YOUR_CDN_BASE_URL - Allows media to be loaded from the CDN.

worker-src 'self' blob:

blob: is used to allow the Worker Scripts to load.

'worker-src' - "[S]pecifies valid sources for Worker, SharedWorker, or ServiceWorker Scripts." (definition from MDN Web Docs)

'self' - "Refers to the origin from which the protected document is being served, including the same URL scheme and port number." (definition from MDN Web Docs)

blob: - "Allows blob: URIs to be used as a content source." (definition from MDN Web Docs)