Safari adds strict CSP support, catches up with other leading browsers
05 October 2021 at 11:09 UTC
Updated: 05 October 2021 at 11:42 UTC
Apple offers users greater defense against XSS and other vulnerabilities
Safari, the default browser for Apple devices, will soon employ a much-needed security feature to better protect against script-injection attacks.
According to a thread on the bug-tracking platform for WebKit, the browser engine that powers Safari, Apple’s developers have added support for strict Content Security Policy (CSP) to WebKit Nightly, the preview release of the engine.
Discussions concerning the addition of the strict CSP have been ongoing since 2018, the thread shows.
The technical detail
The original CSP specification was inflexible and limited, which forced developers to make compromises on the security of their web applications. Strict CSP, marked by the directive, addresses these shortcomings.
“Without , the CSP has to include a list of hosts where the page is allowed to load scripts from,” Dominic Couture, senior application security engineer at GitLab, told The Daily Swig.
“This is a tedious task and there are risks of CSP bypasses if the attacker is able to host scripts on one of the allow-listed hosts.”
Strict CSP uses an unpredictable random value called a ‘nonce’ that the web application safely generates on the server-side to validate the scripts used on the page.
The strict specification makes CSP more manageable for developers and XSS exploits more difficult for attackers.
“Strict CSP strikes the balance between security and flexibility for developers. Therefore, it should make CSP easier to deploy while maintaining security,” browser security engineer Jun Kokatsu told The Daily Swig.
Other major browsers such as Chrome, Safari, and Edge have been supporting this feature for a long time. Safari’s lack of support for has been a point of frustration for developers who wanted to secure their websites across all platforms.
“This is very significant for iOS users, where all browsers are forced to use Safari’s rendering engine (i.e. WebKit),” Kokatsu said.
“In many websites where they chose to deploy Strict CSP, all iOS users were getting fallback CSP mitigation which was basically to allow any scripts (due to Safari not supporting ).”
Couture added: “This new support for will make CSP maintenance easier for engineers thanks to feature-parity across all the major browsers.
“With that said, the biggest impact is for Safari users, who will be more secure on the internet as they will benefit from the same security features as the users of other browsers.”