/** * Detects the current server's Content-Security-Policy to stop the setup if any directive doesn't meet the application's requirements * * @type {{_FindItopVersionInURI: (function(): string|string), aFlags: {bUnsafeInlineScriptOk: boolean, bUnsafeEvalScriptOk: boolean, bUnsafeInlineStyleOk: boolean}, _TestUnsafeEvalScript: SetupCSPDetection._TestUnsafeEvalScript, _HideContinueButtonIfPolicyNotOk: SetupCSPDetection._HideContinueButtonIfPolicyNotOk, _TestUnsafeInlineStyle: SetupCSPDetection._TestUnsafeInlineStyle, Run: SetupCSPDetection.Run, _TestUnSafeInlineScript: SetupCSPDetection._TestUnSafeInlineScript, _AddErrorAlert: SetupCSPDetection._AddErrorAlert}} * @since 2.7.11 3.0.5 3.1.2 3.2.0 N°7075 */ SetupCSPDetection = { aFlags: { bUnsafeInlineScriptOk: false, bUnsafeEvalScriptOk: false, bUnsafeInlineStyleOk: false, }, Run: function () { this._TestUnSafeInlineScript(); this._TestUnsafeEvalScript(); this._TestUnsafeInlineStyle(); this._HideContinueButtonIfPolicyNotOk(); }, /** * Test if the CSP "unsafe-inline" directive for script-src if enabled, otherwise it forbids the setup to go further * @private */ _TestUnSafeInlineScript: function() { var sBaitElemID = "csp-detection--unsafe-inline-script-bait"; // Add inline script that should add an element in the DOM var sAddedScript = ''; $("body").append(sAddedScript); // Check if element has been added to the DOM if ($("#" + sBaitElemID).length === 1) { this.aFlags.bUnsafeInlineScriptOk = true; } else { this._AddErrorAlert("unsafe-inline", "script"); } }, /** * Test if the CSP "unsafe-eval" directive for script-src if enabled, otherwise it forbids the setup to go further * @private */ _TestUnsafeEvalScript: function() { var sBaitElemID = "csp-detection--unsafe-eval-script-bait"; // Add inline eval script that should add an element in the DOM var sAddedScript = ''; $("body").append(sAddedScript); // Check if element has been added to the DOM if ($("#" + sBaitElemID).length === 1) { this.aFlags.bUnsafeEvalScriptOk = true; } else { this._AddErrorAlert("unsafe-eval", "script"); } }, /** * Test if the CSP "unsafe-inline" directive for style-src if enabled, otherwise it forbids the setup to go further * @private */ _TestUnsafeInlineStyle: function() { var sBaitElemID = "csp-detection--unsafe-inline-style-bait"; // Add inline eval script that should add an element in the DOM $("body").append("