Configuring Custom HTTP Headers
This guide describe how to customize various header configurations of Klevr Portal.
This guide describe how to customize various header configurations of Klevr Portal. It is intended for users that manage CE and portal configuration.
This guide assumes that you have sufficient knowledge and experiecne with configurations of Klevr Portal and the deployment pipeline variables.
Purpose
Purpose of this document is to guide you on how to customize certain configurations of Klevr Portal.
Header Settings Customization
Detailed Instructions:
You can customize the security headers of the portal application based on the customer requirements. This is essential in cases when certain security protocols are to be modified based on specific requirements. You can do this by updating the "Klevr:CustomHeaders" section of configuration.
An example of how the setting would look like is as below.
"CustomHeaders": {
"Default": {
"Headers": {
"X-Content-Type-Options": "nosniff",
"X-Xss-Protection": "1; mode=block",
"Cross-Origin-Resource-Policy": "same-origin"
}
},
"Media": {
"Regex": "(?i)\\.(jpg|png|gif|svg)$",
"Headers": {
"Cross-Origin-Resource-Policy": "cross-origin"
}
},
"API": {
"Regex": "(?i)^(\/abc\/cde)",
"Headers": {
"Cache-Control": "no-cache"
}
}
}
As shown in the above example, each header and it's value can be added as a key-value pair under CustomHeaders -> <section-name> -> Headers. Please note
- <section-name> can be any meaningful name for that section. Ex. Media & API in the above example
- All sections except 'Default' will have a 'Regex' field with a regular expression value. Whenever a request is made to the server, the request URL path is evaluated against the Regex. Only on successful evaluation, the headers under that section will be added. Please make sure to carefully choose your regular expression so that only one evaluates to true for a given request path
- 'Default' section is mandatory, and all the common headers can be added under this section
- 'Default' section header values are always overridden by custom section (Ex. Media) header values. This can used when you have a scenario where you want a default value for a particular header always (Ex. Cross-Origin-Resource-Policy in the above example) and in some cases (like media file requests) you want to change the value to a different one. In that case, you can provide a default value to that header in 'Default -> Header' section and another value for the same in your custom section (Ex. Media -> Header). This way only for media requests the header value will be different and for all other cases, it will use the default one
For updating the same in library variable used in pipeline deployment, you can override individal default values, for example: "Klevr.CustomHeaders.Default.Headers.X-Content-Type-Options" = "nosniff". Similarly you can add/update custom sections like "Klevr.CustomHeaders.Media.Headers.X-Content-Type-Options" = "nosniff"Klevr.CustomHeaders.Media". You can add multiple variables should you wish to override multiple headers.
The application is capable of substituting the Dynamics URL (only the one associated with the deployed application) if needed to be added to any of the headers. All you need to do is add {DynamicsUrl} in your value string and it will be replaced with the actual URL.
Below are some of the settings added by default. You can edit these to customize the same.
- X-Content-Type-Options: This header indicate that the MIME types advertised in the Content-Type headers should be followed and not be changed. Possible value - 'nosniff'. You can read more about it here.
- X-Xss-Protection: You can find the details and possible value here.
- Referrer-Policy: This header controls how much referrer information (sent with the Referrer header) should be included with requests. You can find the details and possible values here.
- Permissions-Policy: This header provides mechanisms to explicitly declare what functionality can and cannot be used on a website. You can read more about it here.
- Strict-Transport-Security: This header informs browsers that the site should only be accessed using HTTPS. You can find the details and possible values here.
- Cross-Origin-Resource-Policy: This header conveys that the browser blocks no-cors cross-origin/cross-site requests to the given resource. You can find the details and possible values here.
- Cross-Origin-Opener-Policy: This header allows you to ensure a top-level document does not share a browsing context group with cross-origin documents. You can find the details and possible values here.
- Cross-Origin-Embedder-Policy: This header configures embedding cross-origin resources into the document. Possible values are as below.unsafe-none: This is the default value. Allows the document to fetch cross-origin resources without giving explicit permission through the CORS protocol or the Cross-Origin-Resource-Policy header. require-corp: A document can only load resources from the same origin, or resources explicitly marked as loadable from another origin. If a cross origin resource supports CORS, the crossorigin attribute or the Cross-Origin-Resource-Policy header must be used to load it without being blocked by COEP. credentialless: no-cors cross-origin requests are sent without credentials. In particular, it means Cookies are omitted from the request, and ignored from the response. The responses are allowed without an explicit permission via the Cross-Origin-Resource-Policy header. Navigate responses behave similarly as the require-corp mode: They require Cross-Origin-Resource-Policy response header. You can read more about this header here.
- Content-Security-Policy (CSP): This header is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and data injection attacks. You can configure various settings. Some of the directives used, but not limited to, are listed below. You can find the complete list here.connect-src: This directive restricts the URLs which can be loaded using script interfaces default-src: This directive serves as a fallback for the other CSP fetch directives. List of directives, if missing, will fallback to this directive can be found here. script-src:This directive specifies valid sources for JavaScript. frame-src: This directive specifies valid sources for nested browsing. Specifying a URL will mark that as a valid source for any content to be loaded from. Example: You can provide the base URL of YouTube which will allow any videos from YouTube to be loaded within the portal which would otherwise be blocked. font-src: This directive specifies valid sources for fonts. style-src:This directive specifies valid sources for stylesheets. img-src: This directive specifies valid sources of images and favicons. frame-ancestors: This directive specifies valid parents that may embed a page of this application. You can read more about this header policy here & here. For an example of this policy with connect-src & default-src, you can refer the example JSON mentioned above. You can extend this policy by adding more directives.
Last updated on