Fix #14422 and add more thorough check for CSP violations

/cc @gibson042, @dmethvin