Skip to content

Commit 75e3a18

Browse files
committed
add csp hash
1 parent 807644f commit 75e3a18

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Ajax/JsUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,8 @@ public function _add_event($element, $js, $event, $preventDefault = false, $stop
513513
public function getInjected() {
514514
return $this->injected;
515515
}
516+
517+
public function setParam(string $param,$value){
518+
$this->params[$param]=$value;
519+
}
516520
}

Ajax/php/ubiquity/JsUtils.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ class JsUtils extends \Ajax\JsUtils {
1515
*/
1616
protected function _open_script($src = '') {
1717
$str = '<script ';
18-
if (($this->params['nonce']??false) && ContentSecurityManager::isStarted()) {
18+
if (($this->params['csp']??false)==='nonce' && ContentSecurityManager::isStarted()) {
1919
$nonce = ContentSecurityManager::getNonce('jsUtils');
2020
$str .= ' nonce="' . $nonce . '" ';
2121
}
2222
$str .= ($src == '') ? '>' : ' src="' . $src . '">';
2323
return $str;
2424
}
2525

26+
public function inline($script, $cdata = true) {
27+
if (($this->params['csp']??false)==='hash' && ContentSecurityManager::isStarted()) {
28+
$script= ($cdata) ? "\n// <![CDATA[\n{$script}\n// ]]>\n" : "\n{$script}\n";
29+
ContentSecurityManager::getHash('jsUtils',$script);
30+
}
31+
return $this->_open_script().$script.$this->_close_script();
32+
}
33+
34+
2635
public function getUrl($url) {
2736
return URequest::getUrl($url);
2837
}

0 commit comments

Comments
 (0)