Skip to content

Commit e15b536

Browse files
authored
Merge pull request #101 from bkraul/develop-1.3.x
Corrections to csp issues with preview button. Corrections to image p…
2 parents fb95072 + f935075 commit e15b536

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

Diff for: BBCodePlus/BBCodePlus.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class BBCodePlusPlugin extends MantisFormattingPlugin {
1111
private $t_MantisCoreFormatting_process_urls = OFF;
1212
private $t_bbCode = null;
1313
private $t_HTML = null;
14+
private $t_nonceToken = null;
1415
//-------------------------------------------------------------------
1516
/**
1617
* A method that populates the plugin information and minimum requirements.
@@ -21,7 +22,7 @@ function register() {
2122
$this->name = plugin_lang_get( 'title' );
2223
$this->description = plugin_lang_get( 'description' );
2324
$this->page = 'config';
24-
$this->version = '1.3.17';
25+
$this->version = '1.3.18';
2526

2627
$this->requires['MantisCore'] = '1.3.0';
2728
# this plugin can coexist with MantisCoreFormatting.
@@ -68,6 +69,8 @@ function init() {
6869
$this->t_MantisCoreFormatting_process_text = $this->t_MantisCoreFormatting && config_get( 'plugin_MantisCoreFormatting_process_text' );
6970
$this->t_MantisCoreFormatting_process_urls = $this->t_MantisCoreFormatting && config_get( 'plugin_MantisCoreFormatting_process_urls' );
7071
}
72+
# create the random nonce token for allowing unsafe-eval on csp
73+
$this->t_nonceToken = base64_encode(substr(md5(mt_rand()), 0, 12));
7174
}
7275
//-------------------------------------------------------------------
7376
/**
@@ -107,6 +110,7 @@ function csp_headers() {
107110
if ( (ON == plugin_config_get( 'process_markitup' )) && function_exists( 'http_csp_add' ) ) {
108111
http_csp_add( 'img-src', "*" );
109112
http_csp_add( 'frame-ancestors', "'self'" );
113+
http_csp_add( 'script-src', "'nonce-$this->t_nonceToken'");
110114
}
111115
}
112116
//-------------------------------------------------------------------
@@ -118,23 +122,23 @@ function csp_headers() {
118122
function resources( $p_event ) {
119123
# includes.
120124
$resources = '<link rel="stylesheet" type="text/css" href="' . plugin_file( 'bbcodeplus.css' ) . '" />';
121-
$resources .= '<script type="text/javascript" src="' . plugin_file( 'bbcodeplus-init.js' ) . '"></script>';
125+
$resources .= '<script type="text/javascript" src="' . plugin_file( 'bbcodeplus-init.js' ) . '" nonce="' . $this->t_nonceToken . '"></script>';
122126

123127
if ( ON == plugin_config_get( 'process_markitup' ) ) {
124128
$resources .= '<link rel="stylesheet" type="text/css" href="' . plugin_file( 'markitup/skins/' . plugin_config_get( 'markitup_skin' ) . '/style.css' ) . '" />';
125129
$resources .= '<link rel="stylesheet" type="text/css" href="' . plugin_file( 'markitup/sets/mantis/style.css' ) . '" />';
126-
$resources .= '<script type="text/javascript" src="' . plugin_file( 'markitup/jquery_markitup.js' ) . '"></script>';
127-
$resources .= '<script type="text/javascript" src="' . plugin_file( 'markitup/sets/mantis/set.js' ) . '"></script>';
128-
$resources .= '<script type="text/javascript" src="' . plugin_file( 'markitup-init.js' ) . '"></script>';
130+
$resources .= '<script type="text/javascript" src="' . plugin_file( 'markitup/jquery_markitup.js' ) . '" nonce="' . $this->t_nonceToken . '"></script>';
131+
$resources .= '<script type="text/javascript" src="' . plugin_file( 'markitup/sets/mantis/set.js' ) . '" nonce="' . $this->t_nonceToken . '"></script>';
132+
$resources .= '<script type="text/javascript" src="' . plugin_file( 'markitup-init.js' ) . '" nonce="' . $this->t_nonceToken . '"></script>';
129133
}
130134

131135
if ( ON == plugin_config_get( 'process_highlight' ) ) {
132136
$resources .= '<link rel="stylesheet" type="text/css" href="' . plugin_file( 'prism/styles/' . plugin_config_get( 'highlight_css' ) . '.css' ) . '" />';
133-
$resources .= '<script type="text/javascript" src="' . plugin_file( 'prism/prism.js' ) . '"></script>';
137+
$resources .= '<script type="text/javascript" src="' . plugin_file( 'prism/prism.js' ) . '" nonce="' . $this->t_nonceToken . '"></script>';
134138

135139
# load additional languages.
136140
if ( ON == plugin_config_get( 'highlight_extralangs' ) ) {
137-
$resources .= '<script type="text/javascript" src="' . plugin_file( 'prism/prism_additional_languages.js' ) . '"></script>';
141+
$resources .= '<script type="text/javascript" src="' . plugin_file( 'prism/prism_additional_languages.js' ) . '" nonce="' . $this->t_nonceToken . '"></script>';
138142
}
139143
}
140144

Diff for: BBCodePlus/files/markitup/jquery_markitup.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,7 @@
220220
}).bind("focusin.markItUp", function(){
221221
$$.focus();
222222
}).bind('mouseup', function(e) {
223-
if (button.call) {
224-
eval(button.call)(e); // Pass the mouseup event to custom delegate
225-
}
223+
if (button.call == 'preview') { preview(); }
226224
setTimeout(function() { markup(button) },1);
227225
return false;
228226
}).bind('mouseenter.markItUp', function() {

Diff for: BBCodePlus/files/markitup/sets/mantis/set.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ mySettings = {
194194
// create a new list of images.
195195
body.append("<ul></ul>")
196196
var list = body.children('ul');
197+
197198
// append thumbnail classes.
198199
list.attr("class", "bbcodeplus image-picker");
199200

200201
$(".bug-attachment-preview-image a img").each(function(index, value) {
201-
var imgUrl = this.src;
202-
202+
var imgUrl = $(this).parent().prop('href');
203203
var img = $("<li><a href=\"#\"><img src=\"" + imgUrl + "\"></a></li>");
204204
var link = img.children('a');
205205
link.click(function() {

0 commit comments

Comments
 (0)