GHSA-cfh4-7wq9-6pgg

Suggest an improvement
Source
https://github.com/advisories/GHSA-cfh4-7wq9-6pgg
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/06/GHSA-cfh4-7wq9-6pgg/GHSA-cfh4-7wq9-6pgg.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-cfh4-7wq9-6pgg
Aliases
Published
2023-06-30T20:35:37Z
Modified
2024-02-16T08:15:34.684315Z
Severity
  • 6.5 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N CVSS Calculator
Summary
WPGraphQL Plugin vulnerable to Server Side Request Forgery (SSRF)
Details

Impact

Users with capabilities to upload media (editors and above) are succeptible to SSRF (Server-Side Request Forgery) when executing the createMediaItem Mutation.

Authenticated users making GraphQL requests that execute the createMediaItem could pass executable paths in the mutations filePath argument that could give them unwarranted access to the server.

It's recommended to update to WPGraphQL v1.14.6 or newer. If you're unable to do so, below is a snippet you can add to your functions.php (or similar) that filters the createMediaItem mutation's resolver.

Patches

  • v1.14.6
  • https://github.com/wp-graphql/wp-graphql/pull/2840

Workarounds

If you're unable to upgrade to v1.14.6 or higher, you should be able to use the following snippet in your functions.php to override the vulnerable resolver.

This snippet has been tested as far back as WPGraphQL v0.15

add_filter( 'graphql_pre_resolve_field', function( $nil, $source, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info, $type_name, $field_key, $field, $field_resolver ) {

    if ( $info->fieldName !== 'createMediaItem' ) {
        return $nil;
    }

    $input = $args['input'] ?? null;

        if ( ! isset( $input['filePath'] ) ) {
        return $nil;
    }

    $uploaded_file_url   = $input['filePath'];

    // Check that the filetype is allowed
    $check_file = wp_check_filetype( $uploaded_file_url );

    // if the file doesn't pass the check, throw an error
    if ( ! $check_file['ext'] || ! $check_file['type'] || ! wp_http_validate_url( $uploaded_file_url ) ) {
        throw new \GraphQL\Error\UserError( sprintf( __( 'Invalid filePath "%s"', 'wp-graphql' ), $input['filePath'] ) );
    }

    $protocol = wp_parse_url( $input['filePath'], PHP_URL_SCHEME );

    // prevent the filePath from being submitted with a non-allowed protocols
    $allowed_protocols = [ 'https', 'http', 'file' ];

    if ( ! in_array( $protocol, $allowed_protocols, true ) ) {
        throw new \GraphQL\Error\UserError( sprintf( __( 'Invalid protocol. "%1$s". Only "%2$s" allowed.', 'wp-graphql' ), $protocol, implode( '", "', $allowed_protocols ) ) );
    }

    return $nil;

}, 10, 9 );

References

  • https://patchstack.com/database/vulnerability/wp-graphql/wordpress-wp-graphql-plugin-1-14-5-server-side-request-forgery-ssrf-vulnerability
Database specific
{
    "nvd_published_at": "2023-11-13T03:15:07Z",
    "cwe_ids": [
        "CWE-918"
    ],
    "severity": "MODERATE",
    "github_reviewed": true,
    "github_reviewed_at": "2023-06-30T20:35:37Z"
}
References

Affected packages

Packagist / wp-graphql/wp-graphql

Package

Name
wp-graphql/wp-graphql
Purl
pkg:composer/wp-graphql/wp-graphql

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
1.14.6

Affected versions

0.*

0.0.2
0.0.3
0.0.5
0.0.20
0.0.21
0.0.22
0.0.23
0.0.24
0.0.25
0.0.26
0.0.27
0.0.28
0.0.29
0.0.30
0.0.31

v0.*

v0.0.6
v0.0.7
v0.0.8
v0.0.9
v0.0.10
v0.0.11
v0.0.12
v0.0.13
v0.0.14
v0.0.15
v0.0.16
v0.0.17
v0.0.18
v0.0.19
v0.0.32
v0.0.33
v0.0.34
v0.1.0
v0.1.1
v0.1.2
v0.1.3
v0.1.4
v0.2.0
v0.2.1
v0.2.2
v0.2.3
v0.3.0
v0.3.01
v0.3.2
v0.3.3
v0.3.4
v0.3.5
v0.3.6
v0.3.7
v0.3.8
v0.4.0
v0.4.1
v0.4.2
v0.4.3
v0.5.0
v0.5.1
v0.6.0
v0.6.1
v0.6.2
v0.6.3
v0.7.0
v0.7.1
v0.8.0
v0.8.1
v0.8.2
v0.8.3
v0.8.4
v0.9.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