Skip to content

Commit bfef564

Browse files
authored
Merge pull request #73 from dartiss/develop
Develop
2 parents 82afce7 + b1f227d commit bfef564

File tree

8 files changed

+71
-68
lines changed

8 files changed

+71
-68
lines changed

.DS_Store

8 KB
Binary file not shown.

assets/.DS_Store

6 KB
Binary file not shown.

includes/add-embeds.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function ce_quick_replace( $content = '', $options = '', $search = '' ) {
141141
$end_pos = strpos( $content, $options['closing_ident'], $start_pos + 1 );
142142

143143
if ( false !== $end_pos ) {
144-
$url = substr( $content, $start_pos + $open_len, $end_pos - $start_pos - $close_len );
144+
$url = substr( $content, $start_pos + strlen( $options['opening_ident'] ), $end_pos - ( $start_pos + strlen( $options['opening_ident'] ) ) );
145145
$file = ce_get_file( $url );
146146
if ( false !== $file ) {
147147
$content = str_replace( $options['opening_ident'] . $url . $options['closing_ident'], $file, $content );

includes/meta-box.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

includes/options-screen.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@
4444
$options['excerpt'] = '';
4545
}
4646

47-
if ( isset( $_POST['code_embed_meta_box'] ) ) {
48-
$options['meta_box'] = sanitize_text_field( wp_unslash( $_POST['code_embed_meta_box'] ) ); // Input var okay.
49-
} else {
50-
$options['meta_box'] = '';
51-
}
52-
5347
update_option( 'artiss_code_embed', $options );
5448

5549
echo '<div class="updated fade"><p><strong>' . esc_html( __( 'Settings saved.', 'simple-embed-code' ) ) . "</strong></p></div>\n";
@@ -58,12 +52,6 @@
5852
// Fetch options into an array.
5953

6054
$options = get_option( 'artiss_code_embed' );
61-
62-
// Display a message box if the custom meta box removal has been overridden.
63-
64-
if ( '1' === $options['meta_box'] ) {
65-
echo '<div class="error fade"><p><strong>' . esc_html( __( 'Warning: You have custom post fields switched on for users who do not have the unfiltered HTML capability. This means that insecure code can be added. Please see the plugin README for more details.', 'simple-embed-code' ) ) . "</strong></p></div>\n";
66-
}
6755
?>
6856

6957
<form method="post" action="<?php echo esc_url( get_bloginfo( 'wpurl' ) ) . '/wp-admin/options-general.php?page=ce-options'; ?>">
@@ -77,13 +65,6 @@
7765
/><?php esc_html_e( 'Allow embedded code to be shown in excerpts', 'simple-embed-code' ); ?></td>
7866
</tr>
7967

80-
<tr>
81-
<th scope="row"><label for="code_embed_meta_box"><?php echo esc_html( ucwords( __( 'Allow custom fields for all users', 'simple-embed-code' ) ) ); ?></label></th>
82-
<td><input type="checkbox" name="code_embed_meta_box" value="1"
83-
<?php checked( '1', $options['meta_box'] ); ?>
84-
/><?php esc_html_e( 'Allows custom meta boxes to be shown for all users, including those without unfiltered HTML permissions.', 'simple-embed-code' ); ?><p class="description"><?php esc_html_e( 'For security purposes, it is recommended that you do not select this option unless you have to. Please the plugin README for more details.' ); ?></p></td>
85-
</tr>
86-
8768
</table>
8869

8970
<?php echo '<h3>' . esc_html( ucwords( __( 'Identifier format', 'simple-embed-code' ) ) ) . '</h3>' . esc_html__( 'Specify the format that will be used to define the way the code is embedded in your post. The formats are case insensitive and characters &lt; &gt [ ] are invalid.', 'simple-embed-code' ); ?>

includes/secure.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Meta boxes
4+
*
5+
* Functions related to meta-box management.
6+
*
7+
* @package simple-embed-code
8+
*/
9+
10+
// Exit if accessed directly.
11+
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit;
14+
}
15+
16+
/**
17+
* Remove Custom Fields
18+
*
19+
* Remove the custom field meta boxes if the user doesn't have the unfiltered HTML permissions.
20+
*
21+
* @param string $post_id Post ID.
22+
* @param string $post Post object.
23+
* @param boolean $update Whether this is an existing post being updated.
24+
*/
25+
function sec_check_post_fields( $post_id, $post, $update ) {
26+
27+
$options = get_option( 'artiss_code_embed' );
28+
29+
// Check if it's an autosave or if the current user has the 'unfiltered_html' capability.
30+
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( current_user_can( 'unfiltered_html' ) ) ) {
31+
return;
32+
}
33+
34+
// Fetch all post meta (custom fields) associated with the post.
35+
$custom_fields = get_post_meta( $post_id );
36+
37+
// If there are custom fields, read through them.
38+
if ( ! empty( $custom_fields ) ) {
39+
40+
foreach ( $custom_fields as $key => $value ) {
41+
42+
// Check to see if any begining with this plugin's prefix.
43+
if ( substr( $key, 0, strlen( $options['keyword_ident'] ) ) === $options['keyword_ident'] ) {
44+
45+
// Filter the meta value.
46+
$new_value = wp_kses_post( $value[0] );
47+
48+
// Now write out the new value.
49+
update_post_meta( $post_id, $key, $new_value );
50+
}
51+
}
52+
}
53+
}
54+
55+
add_action( 'save_post', 'sec_check_post_fields', 10, 3 );

readme.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: code, embed, html, css, javascript
55
Requires at least: 4.6
66
Tested up to: 6.6
77
Requires PHP: 7.4
8-
Stable tag: 2.4
8+
Stable tag: 2.5
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -146,15 +146,13 @@ If you don't wish the output to be full width you can specify a maximum width by
146146

147147
By default embed code will not appear in excerpts. However, you can switch this ability on via the Code Embed options screen. If you do this then the standard rules of excerpts will still apply, but now once the code embed has applied - for example, excerpts are just text, a specific length, etc.
148148

149-
== Custom Field Security ==
149+
== Filtering of code ==
150150

151151
By default, WordPress allows unfiltered HTML to be used by users in post custom fields, even if their role it set up otherwise. This opens up the possibility of leaving a site vulnerable, if any plugins that uses this data doesn't check it appropriately.
152152

153153
"Out of the box", neither the contributor and author roles have unfiltered HTML capabilities but can access custom post fields.
154154

155-
As this plugin requires the use unfiltered HTML, we need to ensure that the only users who use it, should be using it. From version 2.4, this plugin will now turn off custom fields for any users that don't have this capability. This will protect this plugin, but any others too. On the flip side, some users may now loose access to these fields who may still require it.
156-
157-
For this reason, there is an option in the Code Embed settings screen to turn them back on for all users. Please use this ONLY if it really is needed. I would recommend looking at giving those users different, or modified roles, with the appropriate permissions instead of overridding it here. But the choice is yours.
155+
As this plugin requires the use unfiltered HTML, we need to ensure that the only users who use it, should be using it. From version 2.5, any users without this permission that update a post containing embeds from this plugin will cause the code to be filtered.
158156

159157
== Reviews & Mentions ==
160158

@@ -179,9 +177,11 @@ Voila! It's ready to go.
179177

180178
= My code doesn't work =
181179

182-
If your code contains the characters `]]>` then you'll find that it doesn't - WordPress modifies this itself.
180+
If your code contains the characters `]]>` then you'll find that it doesn't - WordPress modifies this itself.
181+
182+
Also, check to see if the post has been modified by a user without `unfiltered_html` permissions - if it was, they may have caused the code to have been modified (see the "Filtering of code" section above).
183183

184-
Otherwise, it's likely to be your code and not this plugin. The best way to confirm this is to look at the source of the page and compare the code output with what you embedded. Does it match? If it does, then your code is at fault.
184+
Otherwise, it's likely to be your code and not this plugin. The best way to confirm this is to look at the source of the page and compare the code output with what you embedded. Does it match? If it does, then your code is at fault.
185185

186186
= What's the maximum size of the embed code that I can save in a custom field? =
187187

@@ -207,6 +207,10 @@ It is, in that it doesn't save any data that could be odds with GDPR compliance
207207

208208
I use semantic versioning, with the first release being 1.0.
209209

210+
= 2.5 =
211+
* Enhancement: This release is a revised version of 2.4, with less impact to other plugins and users. See the README for more details, but this undoes the changes in 2.4 and adds in filtering of code embed fields for users without the correct permissions.
212+
* Bug: Fixed a long time bug that could cause an infinite loop to occur in rare situations
213+
210214
= 2.4 =
211215
* Enhancement: A vulnerability was raised to me but is actually an issue with Core. I've implemented a fix that protects not just this plugin but any others you may have installed. Please read the section in the README titled "Custom Field Security" for more details
212216
* Enhancement: Tweaked a few bits of code here. No visible changes, just quality improvements
@@ -348,5 +352,5 @@ versions of this plugin
348352

349353
== Upgrade Notice ==
350354

351-
= 2.4 =
355+
= 2.5 =
352356
* Important security update

simple-code-embed.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Plugin Name: Code Embed
1010
* Plugin URI: https://wordpress.org/plugins/simple-embed-code/
1111
* Description: Code Embed provides a very easy and efficient way to embed code (JavaScript and HTML) in your posts and pages.
12-
* Version: 2.4
12+
* Version: 2.5
1313
* Requires at least: 4.6
1414
* Requires PHP: 7.4
1515
* Author: David Artiss
@@ -26,7 +26,7 @@
2626
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2727
*/
2828

29-
define( 'CODE_EMBED_VERSION', '2.4' );
29+
define( 'CODE_EMBED_VERSION', '2.5' );
3030

3131
// Define global to hold the plugin base file name.
3232

@@ -48,4 +48,4 @@
4848

4949
require_once $functions_dir . 'screens.php'; // Add settings and tools screens.
5050

51-
require_once $functions_dir . 'meta-box.php'; // Suppress meta-boxes.
51+
require_once $functions_dir . 'secure.php'; // Security functionality.

0 commit comments

Comments
 (0)