Skip to content

Commit

Permalink
Merge pull request #63 from Automattic/hotfix/path-check-for-private-dir
Browse files Browse the repository at this point in the history
Fix the private path directory not being valid
  • Loading branch information
ingeniumed authored Dec 5, 2023
2 parents 0c69750 + a900531 commit 707b71d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
31 changes: 24 additions & 7 deletions governance/governance-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,33 @@ public static function get_governance_rules_json() {
* @param string $governance_file_path Path to the governance file.
* @param array $filter_options Options that can be used as a filter for determining the right file.
*/
$governance_file_path = apply_filters( 'vip_governance__governance_file_path', $governance_file_path, $filter_options );
$filter_file_path = apply_filters( 'vip_governance__governance_file_path', $governance_file_path, $filter_options );

// Make sure the path is normalized. Note that file_exists() is still.
$governance_file_path = realpath( $governance_file_path );
// Make sure the path is normalized. Note that file_exists() is still needed at times.
$filter_file_path = realpath( $filter_file_path );

// Make sure the file exists and is in the wp-content/ directory.
if ( ! file_exists( $governance_file_path ) ) {
// if the value is false, throw a file not found error right away.
if ( false === $filter_file_path ) {
return new WP_Error( 'governance-file-not-found', __( 'Governance rules could not be found.', 'vip-governance' ) );
} elseif ( substr( $governance_file_path, 0, strlen( WP_CONTENT_DIR ) ) !== WP_CONTENT_DIR ) {
return new WP_Error( 'governance-file-not-in-wp-content', __( 'Governance rules must be stored within the wp-content/ directory or a subdirectory.', 'vip-governance' ) );
}

// Make sure the file is under wp-content or private directory.
if ( $filter_file_path && $filter_file_path !== $governance_file_path ) {
$is_in_wp_content = substr( $filter_file_path, 0, strlen( WP_CONTENT_DIR ) ) === WP_CONTENT_DIR;
$is_in_private = defined( 'WPCOM_VIP_PRIVATE_DIR' ) ? substr( $filter_file_path, 0, strlen( WPCOM_VIP_PRIVATE_DIR ) ) === WPCOM_VIP_PRIVATE_DIR : false;

if ( ! $is_in_wp_content && ! $is_in_private ) {
/* translators: %s: filter file name */
return new WP_Error( 'governance-file-not-in-wp-content-or-private', sprintf( __( 'Governance rules (%s) must be stored under the wp-content or private directory/subdirectory.', 'vip-governance' ), $filter_file_path ) );
}
}

$governance_file_path = $filter_file_path;

// Make sure the file exists.
if ( ! file_exists( $governance_file_path ) ) {
/* translators: %s: governance file name */
return new WP_Error( 'governance-file-not-found', sprintf( __( 'Governance rules (%s) could not be found.', 'vip-governance' ), $governance_file_path ) );
}

// phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "block-editor-governance",
"version": "1.0.3",
"version": "1.0.4",
"description": "This is a plugin adding additional governance capabilities to the block editor.",
"author": "VIP Bistro",
"main": "build/index.js",
Expand Down
4 changes: 2 additions & 2 deletions vip-governance.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Add additional governance capabilities to the block editor.
* Author: WordPress VIP
* Text Domain: vip-governance
* Version: 1.0.3
* Version: 1.0.4
* Requires at least: 5.9.0
* Tested up to: 6.3.0
* Requires PHP: 7.4
Expand All @@ -20,7 +20,7 @@
if ( ! defined( 'VIP_GOVERNANCE_LOADED' ) ) {
define( 'VIP_GOVERNANCE_LOADED', true );

define( 'WPCOMVIP__GOVERNANCE__PLUGIN_VERSION', '1.0.3' );
define( 'WPCOMVIP__GOVERNANCE__PLUGIN_VERSION', '1.0.4' );
define( 'WPCOMVIP__GOVERNANCE__RULES_SCHEMA_VERSION', '1.0.0' );

if ( ! defined( 'WPCOMVIP_GOVERNANCE_ROOT_PLUGIN_FILE' ) ) {
Expand Down

0 comments on commit 707b71d

Please sign in to comment.