Securing API with jwt
Hey, I am building the apis for the user. After user logs in he receive a JWT token which gives him access to the rest of the APIs.
He now have access to updating his profile picture API which requests two things
1- picture (PNG, gif, jpeg)
2- his Id
After filling these the APIchecks if the id matches the IDhe has in his JWT with claims. If they don't the api will return "Unauthorized".
However a user can easily mess around with JWT and change the claims values. He can change the role from User to Admin, he can change his Id in the claims too!
I can stop asking the user for the id and just get it directly from the jwt token, but it is still not secure enough.
thank you for your help
15 Replies
The last section of a JWT is the signature
If the token is modified in any way, the signature will be incorrect
So just validate the signature as part of the pipeline
doesn't asp.net validate the signature on its own?
Asp has no built in support for JWTs at sll
Bearer
i mean
So what are you using for it?
shouldnt thise do it?
let me test this and modify the jwt
are you doing
AddAuthentication().AddJwtBearer(...)
somewhere?you were right
and all you did was modify the claims right?
you didnt outright remove the signature
No
i just modified the claims
k
good 🙂
Okay so do i even need to ask for the users id in the api?
since i have it in the token
probably not
this is awesome and so secure
thank you!