Skip to content

Commit

Permalink
Add validation in the post job to prevent add external images
Browse files Browse the repository at this point in the history
This validation test the new image path against the upload dir.
  • Loading branch information
renatho committed Apr 6, 2020
1 parent 82c2631 commit d7954bb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions includes/forms/class-wp-job-manager-form-submit-job.php
Expand Up @@ -407,6 +407,22 @@ protected function validate_fields( $values ) {
}
}
}
if ( 'file' === $field['type'] ) {
if ( is_array( $values[ $group_key ][ $key ] ) ) {
$check_value = array_filter( $values[ $group_key ][ $key ] );
} else {
$check_value = array_filter( [ $values[ $group_key ][ $key ] ] );
}
if ( ! empty( $check_value ) ) {
foreach ( $check_value as $file_url ) {
$baseurl = wp_upload_dir()['baseurl'];

if ( ! is_numeric( $file_url ) && false === strpos( $file_url, $baseurl ) ) {
throw new Exception( __( 'Invalid image path.', 'wp-job-manager' ) );
}
}
}
}
if ( empty( $field['file_limit'] ) && empty( $field['multiple'] ) ) {
$field['file_limit'] = 1;
}
Expand Down

0 comments on commit d7954bb

Please sign in to comment.