amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Auth allows update for items from different owners

Open shivangp opened this issue 6 years ago • 4 comments

I'm trying to create an amplify API that allows users to store the profile information in a User table in Dynamo DB. I'm using @auth directive to set owner for the and want to make sure users can only update their own profile. My schema is as follows where ID is the ID from my cognito user pool:

type User
	@model(subscriptions: { level: public })
	@auth(
		rules: [
			{ allow: public, provider: iam, operations: [read] }
			{
				allow: owner
				ownerField: "id"
				identityClaim: "sub"
				operations: [read, create, update]
			}
			{ allow: groups, groups: ["CommunityAdmin"] }
		]
	)
	@key(fields: ["id"])
	@key(
		name: "byUsername"
		fields: ["username"]
		queryField: "userByUsername"
	) {
	id: ID!
	identityId: String
	email: String!
	username: String!
	about: String	
}

From the appsync console I'm logged in as a user from my user pool and if I try to perform following update mutation, it will allow me to update another user's about field:

mutation {
  updateUser(input: {
    	id:"<SOME OTHER USER ID>",
    	about:"Test update"
  }) {
    id
    username
    about
  }
}

How can setup @auth so only the owner can only update their own profile?

shivangp avatar Feb 08 '20 11:02 shivangp

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 09 '20 01:05 stale[bot]

@shivangp Looking into this. Will try to duplicate and resolve.

mtliendo avatar May 13 '20 04:05 mtliendo

from the appsync console I'm logged in as a user from my user pool and if I try to perform following update mutation, it will allow me to update another user's about field:

Does the user that you're using in AppSync console belong to CommunityAdmin? If the user does not belong to this group, they would not be allowed to update any record other than the one they own.

yuth avatar Aug 22 '20 00:08 yuth

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 22:05 github-actions[bot]