Skip to content

Commit 82afce7

Browse files
authored
Merge pull request #70 from dartiss/develop
Version 2.4
2 parents 0780c91 + e6e0a2f commit 82afce7

File tree

5 files changed

+119
-34
lines changed

5 files changed

+119
-34
lines changed

includes/meta-box.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 $screen The screen identifier.
22+
* @param string $context The screen context for which to display meta boxes.
23+
* @param boolean $data_object Gets passed to the meta box callback function as the first parameter.
24+
*/
25+
function sec_remove_custom_fields( $screen, $context, $data_object ) {
26+
27+
if ( ! current_user_can( 'unfiltered_html' ) ) {
28+
29+
$options = get_option( 'artiss_code_embed' );
30+
31+
if ( '1' !== $options['meta_box'] ) {
32+
remove_meta_box( 'postcustom', $screen, $context );
33+
}
34+
}
35+
}
36+
37+
add_action( 'do_meta_boxes', 'sec_remove_custom_fields', 1, 3 );

includes/options-screen.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
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+
4753
update_option( 'artiss_code_embed', $options );
4854

4955
echo '<div class="updated fade"><p><strong>' . esc_html( __( 'Settings saved.', 'simple-embed-code' ) ) . "</strong></p></div>\n";
@@ -52,17 +58,32 @@
5258
// Fetch options into an array.
5359

5460
$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+
}
5567
?>
5668

5769
<form method="post" action="<?php echo esc_url( get_bloginfo( 'wpurl' ) ) . '/wp-admin/options-general.php?page=ce-options'; ?>">
5870

5971
<table class="form-table">
72+
6073
<tr>
6174
<th scope="row"><label for="code_embed_excerpt"><?php echo esc_html( ucwords( __( 'Allow in excerpts', 'simple-embed-code' ) ) ); ?></label></th>
6275
<td><input type="checkbox" name="code_embed_excerpt" value="1"
6376
<?php checked( '1', $options['excerpt'] ); ?>
6477
/><?php esc_html_e( 'Allow embedded code to be shown in excerpts', 'simple-embed-code' ); ?></td>
6578
</tr>
79+
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+
6687
</table>
6788

6889
<?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/shared.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
* @package simple-embed-code
88
*/
99

10+
// Exit if accessed directly.
11+
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit;
14+
}
15+
1016
/**
1117
* Add meta to plugin details
1218
*
@@ -62,33 +68,42 @@ function sec_action_links( $actions, $plugin_file ) {
6268
add_filter( 'plugin_action_links', 'sec_action_links', 10, 2 );
6369

6470
/**
65-
* WordPress Fork Check
71+
* WordPress Requirements Check
6672
*
67-
* Deactivate the plugin if an unsupported fork of WordPress is detected.
73+
* Deactivate the plugin if certain requirements are not met.
6874
*
69-
* @version 1.0
75+
* @version 1.1
7076
*/
71-
function sec_fork_check() {
77+
function sec_requirements_check() {
78+
79+
$reason = '';
80+
81+
// Grab the plugin details.
82+
83+
$plugins = get_plugins();
84+
$name = $plugins[ CODE_EMBED_PLUGIN_BASE ]['Name'];
7285

7386
// Check for a fork.
7487

7588
if ( function_exists( 'calmpress_version' ) || function_exists( 'classicpress_version' ) ) {
7689

77-
// Grab the plugin details.
90+
/* translators: 1: The plugin name. */
91+
$reason .= '<li>' . sprintf( __( 'A fork of WordPress was detected. %1$s has not been tested on this fork and, as a consequence, the author will not provide any support.', 'simple-embed-code' ), $name ) . '</li>';
92+
93+
}
7894

79-
$plugins = get_plugins();
80-
$name = $plugins[ CODE_EMBED_PLUGIN_BASE ]['Name'];
95+
// If a requirement is not met, output the message and stop the plugin.
96+
97+
if ( '' !== $reason ) {
8198

8299
// Deactivate this plugin.
83100

84-
deactivate_plugins( CODE_EMBED_PLUGIN_BASE );
101+
deactivate_plugins( PLUGIN_NAME_PLUGIN_BASE );
85102

86103
// Set up a message and output it via wp_die.
87104

88105
/* translators: 1: The plugin name. */
89-
$message = '<p><b>' . sprintf( __( '%1$s has been deactivated', 'simple-embed-code' ), $name ) . '</b></p><p>' . __( 'Reason:', 'simple-embed-code' ) . '</p>';
90-
/* translators: 1: The plugin name. */
91-
$message .= '<ul><li>' . __( 'A fork of WordPress was detected.', 'simple-embed-code' ) . '</li></ul><p>' . sprintf( __( 'The author of %1$s will not provide any support until the above are resolved.', 'simple-embed-code' ), $name ) . '</p>';
106+
$message = '<p><b>' . sprintf( __( '%1$s has been deactivated', 'simple-embed-code' ), $name ) . '</b></p><p>' . __( 'Reason:', 'simple-embed-code' ) . '</p><ul>' . $reason . '</ul>';
92107

93108
$allowed = array(
94109
'p' => array(),
@@ -101,4 +116,4 @@ function sec_fork_check() {
101116
}
102117
}
103118

104-
add_action( 'admin_init', 'sec_fork_check' );
119+
add_action( 'admin_init', 'sec_requirements_check' );

readme.txt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Contributors: dartiss
33
Donate link: https://artiss.blog/donate
44
Tags: code, embed, html, css, javascript
55
Requires at least: 4.6
6-
Tested up to: 6.5
6+
Tested up to: 6.6
77
Requires PHP: 7.4
8-
Stable tag: 2.3.9
8+
Stable tag: 2.4
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111

@@ -62,9 +62,11 @@ Check out the screenshots for how the custom fields should look.
6262

6363
== I can't find the custom fields ==
6464

65-
For block editor users, I'm assuming you've done the above. For classic editor users, the custom fields should be present by default. In all cases they should appear at the bottom of the editor screen.
65+
For block editor users, I'm assuming you've done the above. For classic editor users, the custom fields should be present by default. In all cases they should appear at the bottom of the editor screen.
66+
67+
From version 2.4, anyone without the "unfiltered HTML" capability won't be able to see custom fields, for added security. Please see the section "Custom Field Security", below, for more details.
6668

67-
If they're not present then you may have a theme or plugin that removes this or may have a problem with your WordPress installation - you will need to try the usual diagnostics to try and resolve this, including requesting help on [the WordPress support forum](https://wordpress.org/support/forum/how-to-and-troubleshooting/ "Fixing WordPress Forum").
69+
If none of the above applies then you may have a theme or plugin that removes this or may have a problem with your WordPress installation - you will need to try the usual diagnostics to try and resolve this, including requesting help on [the WordPress support forum](https://wordpress.org/support/forum/how-to-and-troubleshooting/ "Fixing WordPress Forum").
6870

6971
Please bear in mind that the custom fields functionality is part of WordPress so it would be greatly appreciated if you don't give me poor reviews in this situation as, I say, this component is not part of this plugin but, by using it, keeps this plugin simple to use and bloat-free :)
7072

@@ -142,7 +144,17 @@ If you don't wish the output to be full width you can specify a maximum width by
142144

143145
== Embedding in excerpts ==
144146

145-
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.
147+
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.
148+
149+
== Custom Field Security ==
150+
151+
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.
152+
153+
"Out of the box", neither the contributor and author roles have unfiltered HTML capabilities but can access custom post fields.
154+
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.
146158

147159
== Reviews & Mentions ==
148160

@@ -152,8 +164,8 @@ By default embed code will not appear in excerpts. However, you can switch this
152164

153165
[Embedding content](http://wsdblog.westbrook.k12.me.us/blog/2009/12/24/embedding-content/ "Embedding content") - WSD Blogging Server.
154166

155-
[Animating images with PhotoPeach](http://comohago.conectandonos.gov.ar/2009/08/05/animando-imagenes-con-photopeach/ "Animando imágenes con PhotoPeach") - Cómo hago.
156-
167+
[Animating images with PhotoPeach](http://comohago.conectandonos.gov.ar/2009/08/05/animando-imagenes-con-photopeach/ "Animando imágenes con PhotoPeach") - Cómo hago.
168+
157169
== Installation ==
158170

159171
Code Embed can be found and installed via the Plugin menu within WordPress administration (Plugins -> Add New). Alternatively, it can be downloaded from WordPress.org and installed manually...
@@ -195,8 +207,12 @@ It is, in that it doesn't save any data that could be odds with GDPR compliance
195207

196208
I use semantic versioning, with the first release being 1.0.
197209

210+
= 2.4 =
211+
* 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
212+
* Enhancement: Tweaked a few bits of code here. No visible changes, just quality improvements
213+
198214
= 2.3.9 =
199-
* Enhancement: So, let me tell you a story. To make the output look neat, I was adding carriage returns to the embeds. Except, if you want to embed something part way through a line it can look... well... wrong. And all for it looking clean. Remember kids, cleanlyness isn't always next to Godlyness. Needless to say, those rogue carriage returns are gone
215+
* Enhancement: So, let me tell you a story. To make the output look neat, I was adding carriage returns to the embeds. Except, if you want to embed something part way through a line it can look... well... wrong. And all for it looking clean. Remember kids, cleanliness isn't always next to Godliness. Needless to say, those rogue carriage returns are gone
200216
* Enhancement: Whilst I was at it, I updated some of the settings code to a brand-spanking new version, which I'm sharing across all my plugins
201217
* Enhancement: Tidied up some of the assets, including adding a blueprint for WordPress Playground
202218

@@ -332,5 +348,5 @@ versions of this plugin
332348

333349
== Upgrade Notice ==
334350

335-
= 2.3.9 =
336-
* Minor improvement to output to eliminate unwanted carriage returns
351+
= 2.4 =
352+
* Important security update

simple-code-embed.php

Lines changed: 8 additions & 12 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.3.9
12+
* Version: 2.4
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.3.9' );
29+
define( 'CODE_EMBED_VERSION', '2.4' );
3030

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

@@ -38,18 +38,14 @@
3838

3939
$functions_dir = plugin_dir_path( __FILE__ ) . 'includes/';
4040

41-
require_once $functions_dir . 'initialise.php'; // Initialisation scripts.
41+
require_once $functions_dir . 'initialise.php'; // Initialisation scripts.
4242

43-
if ( is_admin() ) {
43+
require_once $functions_dir . 'add-scripts.php'; // Add scripts to the main theme.
4444

45-
require_once $functions_dir . 'shared.php'; // Functions shared across all my plugins.
45+
require_once $functions_dir . 'add-embeds.php'; // Filter to apply code embeds.
4646

47-
require_once $functions_dir . 'screens.php'; // Add settings and tools screens.
47+
require_once $functions_dir . 'shared.php'; // Functions shared across all my plugins.
4848

49-
} else {
49+
require_once $functions_dir . 'screens.php'; // Add settings and tools screens.
5050

51-
require_once $functions_dir . 'add-scripts.php'; // Add scripts to the main theme.
52-
53-
require_once $functions_dir . 'add-embeds.php'; // Filter to apply code embeds.
54-
55-
}
51+
require_once $functions_dir . 'meta-box.php'; // Suppress meta-boxes.

0 commit comments

Comments
 (0)