Problem: CSP Violation: Previous Page Link Not Functioning
Current Behavior
Steps to reproduce the behavior
1.Navigate to any invalid route For instance http://localhost:63001/invalidwebsite
2. Click on the Back to previous page link displayed on the error page.
4. Observe that nothing happens; the previous page does not load.
5. Open the browser’s developer console and note the CSP (Content Security Policy) error indicating that the inline JavaScript used by this link has been blocked.
Expected Behavior
When a user clicks the Back to previous page link, the application should successfully navigate to the last visited page. The link should function consistently across all browsers without triggering any CSP violations, using an approved and CSP-compliant JavaScript implementation.
Possible Solution
Move the inline JavaScript used by the Back to previous page link into an external JavaScript file. This will ensure the functionality complies with the site’s Content Security Policy, prevent CSP blocking, and restore proper back navigation behavior.
Context and Notes
This issue prevents the Back to previous page link from functioning, which impacts navigation and interrupts the user experience on error pages. My goal is to ensure the link works reliably without triggering CSP violations.
To diagnose the problem, I reviewed the browser console and identified that the inline JavaScript was being blocked by the existing Content Security Policy.
I tested a fix by moving the inline JavaScript into an external file, and this removed the CSP warnings and restored the expected behavior. I will be creating a pull request with this solution.
Version used
AtoM 2.10
Operating System and version
macOS Sonoma 14.5
Default installation culture
en
PHP version
PHP 8.3.1