File tree Expand file tree Collapse file tree 3 files changed +18
-21
lines changed Expand file tree Collapse file tree 3 files changed +18
-21
lines changed Original file line number Diff line number Diff line change 33.settings /*
44doxygeneJquery
55doc /*
6+ .idea /
Original file line number Diff line number Diff line change @@ -73,27 +73,10 @@ protected function minify($input) {
7373 */
7474 protected function _open_script ($ src = '' ) {
7575 $ str = '<script ' ;
76- if (! $ this ->isAjax () && isset ($ this ->params ['nonce ' ])) {
77- $ nonce = $ this ->nonce ?? $ this ->generateNonce ($ this ->params ['nonce ' ]);
78- $ str .= ' nonce=" ' . $ nonce . '" ' ;
79- }
8076 $ str .= ($ src == '' ) ? '> ' : ' src=" ' . $ src . '"> ' ;
8177 return $ str ;
8278 }
8379
84- protected function onNonce () {}
85-
86- protected function generateNonce ($ value = null ): string {
87- $ bytes = \random_bytes ((int ) ($ value ?? 32 ));
88- $ this ->nonce = \base64_encode ($ bytes );
89- $ this ->onNonce ();
90- return $ this ->nonce ;
91- }
92-
93- public function getNonce () {
94- return $ this ->nonce ;
95- }
96-
9780 /**
9881 * Outputs an closing </script>
9982 *
@@ -111,8 +94,4 @@ protected function conflict() {
11194 public function addToCompile ($ jsScript ) {
11295 $ this ->_addToCompile ($ jsScript );
11396 }
114-
115- public function isAjax (): bool {
116- return (isset ($ _SERVER ['HTTP_X_REQUESTED_WITH ' ]) && ! empty ($ _SERVER ['HTTP_X_REQUESTED_WITH ' ]) && strtolower ($ _SERVER ['HTTP_X_REQUESTED_WITH ' ]) == 'xmlhttprequest ' );
117- }
11897}
Original file line number Diff line number Diff line change 33
44use Ubiquity \controllers \Startup ;
55use Ubiquity \utils \http \URequest ;
6+ use Ubiquity \security \csp \ContentSecurityManager ;
67
78class JsUtils extends \Ajax \JsUtils {
89
10+ /**
11+ * Outputs an opening <script>
12+ *
13+ * @param string $src
14+ * @return string
15+ */
16+ protected function _open_script ($ src = '' ) {
17+ $ str = '<script ' ;
18+ if (isset ($ this ->params ['nonce ' ]) && ContentSecurityManager::isStarted ()) {
19+ $ nonce = ContentSecurityManager::getNonce ('jsUtils ' );
20+ $ str .= ' nonce=" ' . $ nonce . '" ' ;
21+ }
22+ $ str .= ($ src == '' ) ? '> ' : ' src=" ' . $ src . '"> ' ;
23+ return $ str ;
24+ }
25+
926 public function getUrl ($ url ) {
1027 return URequest::getUrl ($ url );
1128 }
You can’t perform that action at this time.
0 commit comments