Fix #14422 and add more thorough check for CSP violations