You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe someone found the solution, but i didn't find it.
When I use AWS Amplify and GraphQL mutations to create or update entities (for example, a Recipe template), the fields corresponding to relationships defined with directives like @belongsTo or @hasone accept any ID, even if that ID is invalid or belongs to another user or a non-existent category.
For example, in the following mutation to create a recipe, I can provide a category ID (recipeCategoryId) or profile ID (profileID) that :
Does not exist in the database.
Belongs to a user other than the recipe creator.
constnewRecipe=awaitclient.graphql({query: createRecipe,variables: {input: {title: "test recipe",slug: "test-recipe",image: "imageKey",steps: JSON.stringify([{description: "Step 1",duration: "5 min",step_number: 1}]),recipeCategoryId: "someInvalidCategoryID",profileID: "someOtherUserID",description: "This is a test description",}}});
In this scenario, Amplify does not automatically validate that :
The category ID provided corresponds to an existing valid category.
The profile ID provided matches the current user profile or a valid profile.
This creates potential security loopholes where a malicious user can intercept the request via a tool like Burp Suite, modify the IDs and associate sensitive data with entities to which they should not have access.
Key issues :
Lack of automatic validation: AppSync does not check the existence or validity of linked IDs during mutations.
Insufficient authorization: It is possible to associate an entity (e.g. a recipe) with another entity belonging to a different user without membership verification.
Technical context:
Directives such as @belongsTo(fields: [“profileID”]) or @hasone only define the structure of relationships between entities. However, they do not provide a built-in check of the IDs sent in a mutation.
To solve this problem, custom logic or a lambda-enhanced authorization strategy must be implemented to validate that :
The IDs supplied exist in the database.
The IDs respect the authorizations defined in the schema.
In this case, however, there's no point in using a mutation and there's no point in using a graphql api.
Expected behavior
I want AWS Amplify to automatically check, during mutations, that the IDs I provide (such as profileID or recipeCategoryId) correspond to existing entities and respect authentication rules. Currently, I can supply any ID, even if it's invalid or belongs to another user, which is a security flaw. I need a solution to prevent this behavior.
Reproduction steps
Install basic configuration of react and amplify
create graphql api with 2 model like "Recipe" and "Profile",
Connect cognito user to profile table with owner rules
Create a Recipe and Profile model with @auth relationships and rules.
Ensure that the Recipe template accepts a profileID field that is linked to the Profile template via an @belongsTo relationship.
Add data to the database via the console or frontend application to create profiles and recipes with valid IDs.
Use the createRecipe mutation, sending valid and invalid IDs for the category or profileID field.
Intercept the request with a tool like Burp Suite or DevTools to manipulate the ID sent in the mutation.
Test whether you can insert an ID that doesn't match any existing profile (for example, by sending an ID from another user, or sending a false category id).
domov44
changed the title
GraphQL mutation allows arbitrary IDs for @belongsTo and @hasOne Relationships Without aalidation
GraphQL mutation allows arbitrary IDs for @belongsTo and @hasOne Relationships Without validation
Jan 15, 2025
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
storage
Backend
Amplify CLI
Environment information
Describe the bug
Maybe someone found the solution, but i didn't find it.
When I use AWS Amplify and GraphQL mutations to create or update entities (for example, a Recipe template), the fields corresponding to relationships defined with directives like @belongsTo or @hasone accept any ID, even if that ID is invalid or belongs to another user or a non-existent category.
For example, in the following mutation to create a recipe, I can provide a category ID (recipeCategoryId) or profile ID (profileID) that :
Does not exist in the database.
Belongs to a user other than the recipe creator.
In this scenario, Amplify does not automatically validate that :
The category ID provided corresponds to an existing valid category.
The profile ID provided matches the current user profile or a valid profile.
This creates potential security loopholes where a malicious user can intercept the request via a tool like Burp Suite, modify the IDs and associate sensitive data with entities to which they should not have access.
Key issues :
Lack of automatic validation: AppSync does not check the existence or validity of linked IDs during mutations.
Insufficient authorization: It is possible to associate an entity (e.g. a recipe) with another entity belonging to a different user without membership verification.
Technical context:
Directives such as @belongsTo(fields: [“profileID”]) or @hasone only define the structure of relationships between entities. However, they do not provide a built-in check of the IDs sent in a mutation.
To solve this problem, custom logic or a lambda-enhanced authorization strategy must be implemented to validate that :
The IDs supplied exist in the database.
The IDs respect the authorizations defined in the schema.
In this case, however, there's no point in using a mutation and there's no point in using a graphql api.
Expected behavior
I want AWS Amplify to automatically check, during mutations, that the IDs I provide (such as profileID or recipeCategoryId) correspond to existing entities and respect authentication rules. Currently, I can supply any ID, even if it's invalid or belongs to another user, which is a security flaw. I need a solution to prevent this behavior.
Reproduction steps
Code Snippet
mutation :
graphql schemas :
Log output
aws-exports.js
/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "eu-west-3",
"aws_appsync_graphqlEndpoint": "https://4vv5deajfffsna366kzdwv3a74.appsync-api.eu-west-3.amazonaws.com/graphql",
"aws_appsync_region": "eu-west-3",
"aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
"aws_appsync_apiKey": "da2-7gmjnjkjzvgohiuz2fr6q3cs4a",
"aws_cloud_logic_custom": [
{
"name": "ragApi",
"endpoint": "https://6cpmav12uk.execute-api.eu-west-3.amazonaws.com/ronantest",
"region": "eu-west-3"
}
],
"aws_cognito_identity_pool_id": "eu-west-3:9f2989b5-c818-4346-bc7b-54a51967b910",
"aws_cognito_region": "eu-west-3",
"aws_user_pools_id": "eu-west-3_8wUfDRtHq",
"aws_user_pools_web_client_id": "25klrfh4o0u47tctmp8fbcdu91",
"oauth": {},
"aws_cognito_username_attributes": [],
"aws_cognito_social_providers": [],
"aws_cognito_signup_attributes": [
"EMAIL"
],
"aws_cognito_mfa_configuration": "OFF",
"aws_cognito_mfa_types": [
"SMS"
],
"aws_cognito_password_protection_settings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": []
},
"aws_cognito_verification_mechanisms": [
"EMAIL"
],
"aws_user_files_s3_bucket": "recipesappea0631f8364f439bb0004d59ea016d090e0ef-ronantest",
"aws_user_files_s3_bucket_region": "eu-west-3"
};
export default awsmobile;
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: