Key part
the user agent cannot determine if the inline script was injected by an attacker.
To provide protection, the CSP must prevent the attacker-controlled substrings from running code. Since the user agent does not know which parts of HTML were indicated by untrusted inputs and which come from a template written by a trusted developer, it must accept the worst - that any attribute or element could be controlled by an attacker.
Do you really get any security advantage by extracting all inline-scripts (like JavaScript) to external sources?
No. Retrieving the scripts you want to run does not provide any security benefits; it just allows you to run the scripts you want when using CSP.
The security advantage is the ability to invoke the HTML browser without unintentionally executing scripts that abuse domain privileges or steal secrets.
source share