Privilege Escalation/IDOR allowing anyone to delete and add tags in a question
Categories
(support.mozilla.org :: General, defect)
Tracking
(Not tracked)
People
(Reporter: roldanbrandon62, Assigned: tasos)
References
()
Details
(Keywords: reporter-external, sec-low, wsec-objref, Whiteboard: [reporter-external] [web-bounty-form] [verif?])
SUMMARY
Hi. Normally, the questions.tag_question permission is needed when deleting a tag in a question. Normal users doesnt have this permission. However, i found out, that in the api endpoint, it also allows us to delete tags, and it is missing the permission checks
This is the function for removing a tag
@action(
detail=True, methods=["post", "delete"], permission_classes=[permissions.IsAuthenticated]
)
def remove_tags(self, request, pk=None):
question = self.get_object()
if "tags" not in request.data:
return Response(
{"tags": "This field is required."}, status=status.HTTP_400_BAD_REQUEST
)
tags = request.data["tags"]
for tag in tags:
question.tags.remove(tag)
return Response(status=status.HTTP_204_NO_CONTENT)
As you can see, it lacks the permission check. Here is the original request
@permission_required("questions.tag_question")
@require_POST
def remove_tag(request, question_id):
# FUNCTION BODY HERE
This allow anyone to delete tags in anyone's question
Comment 1•4 years ago
|
||
Hello,
Thank you for your report.
Are you able to reproduce this issue in the application? If so, please provide the steps to reproduce.
Thanks,
Frida
| Reporter | ||
Comment 2•4 years ago
|
||
Not yet, i am unsure yet how tags works and what are the default tags. If you have an account with the tag_question, we can work together and try to reproduce this.
| Reporter | ||
Comment 3•4 years ago
|
||
Oh wait, i think i figured out how the tags works now. Will be making a poc and steps to reproduce now
Comment 4•4 years ago
|
||
I am also checking with the team whether they can grant you or me the tag_question permission.
| Reporter | ||
Comment 5•4 years ago
|
||
So, i found out that a normal user can add the tag needsinfo in a question, when he toggle the Needs More Information Box, below the reply text box. So that will be the tag that we will be using for this poc.
#STEPS TO REPRODUCE
- Have two accounts, we will call these two users as user a and user b
- As user a, make a question
- As user b, reply, and toggle the Needs more information box.
- Now the question has the needsinfo tag.
- As user b, make a post request to
POST /api/2/question/<questionID>/remove_tags/ HTTP/1.1
Host: support.allizom.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://support.allizom.org/en-US/questions/1207230
Content-Type: application/json
X-CSRFToken: IhUtZSJPlM3esR8YfGvnOodPGyh05CbAf4zhVrDtm7kFnuGtKQK0N9YpBBGG8RKg
X-Requested-With: XMLHttpRequest
Content-Length: 22
Origin: https://support.allizom.org
Connection: close
Cookie: csrftoken=IhUtZSJPlM3esR8YfGvnOodPGyh05CbAf4zhVrDtm7kFnuGtKQK0N9YpBBGG8RKg; _ga=GA1.2.375085121.1644585186; session_id=o34zj1xrrlnpilagea8lc1k4cg4uwooy; _gid=GA1.2.1686202550.1648473172; geoip_country_name=Philippines; geoip_country_code=PH; _gat_gtag_UA_36116321_2=1
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
{"tags":["needsinfo"]}
Make sure you provide a proper csrf token.
6. After submitting the following request, the needsinfo tag will be removed
Comment 6•4 years ago
|
||
we gave you (https://support.allizom.org/en-US/user/tomorrowisnew_) tag_question permission in case you want to test the other tags.
So far, I wasn't able to reproduce the issue, I receive 400 bad request response with error: {"tags":"This field is required."}
| Reporter | ||
Comment 7•4 years ago
|
||
Your tags parameter probably is nor being accepted. Here are some thoughts i have, did you set the content type to application/json?
Comment 8•4 years ago
|
||
yes that was the problem, I had to fix the content type. I get 204 No Content response now but the tag is not actually removed using the privileged and non-privileged users. This is the question: https://support.allizom.org/en-US/questions/1207227 and I am testing removing the tag test.
| Reporter | ||
Comment 9•4 years ago
|
||
Nice, are you referring to the tags shown in the right? From what i know, they are not in sync with the real tags of a question with this method. If you add another tag into it, the list of tags will get updated and the test tag will be removed. In reality, the tag is already removed, just not visually
Comment 10•4 years ago
|
||
ok I can confirm the issue now, a user without the tag_question permission is able to remove the tags on the question and I also tested the ability to add tags using /api/2/question/<question-id>/add_tags/ endpoint and it also worked.
Updated•4 years ago
|
| Reporter | ||
Comment 11•4 years ago
|
||
Hi. I am not sure about the add_tags. I think it has a permission check
@action(detail=True, methods=["post"], permission_classes=[permissions.IsAuthenticated])
def add_tags(self, request, pk=None):
# UNIMPORTANT SNIPPET
for tag in tags:
try:
add_existing_tag(tag, question.tags)
except Tag.DoesNotExist:
if request.user.has_perm("taggit.add_tag"): # PERMISSION CHECK
question.tags.add(tag)
else:
raise GenericAPIException(403, "You are not authorized to create new tags.")
data = [{"name": tag.name, "slug": tag.slug} for tag in question.tags.all()]
return Response(data)
But i might be wrong, i havent really tested it yet.
| Reporter | ||
Comment 12•4 years ago
|
||
Nevermind, the add_tag permission check is only required when adding a non existing tag. If we add a tag that already exists, it works normally. Thanks for figuring it out
| Reporter | ||
Comment 13•4 years ago
|
||
Can we change the title to add and remove tags? Thanks
Updated•4 years ago
|
| Assignee | ||
Updated•4 years ago
|
| Assignee | ||
Comment 14•4 years ago
|
||
| Assignee | ||
Comment 15•4 years ago
|
||
Released to prod
| Reporter | ||
Comment 16•4 years ago
|
||
Awesome
| Reporter | ||
Comment 17•4 years ago
|
||
Hi. Any updates on the bounty?
Comment 18•4 years ago
|
||
roldanbrandon62,
Thanks again for this report, yes we will be awarding a bounty, you'll get contacted shortly for payment details.
Updated•4 years ago
|
Comment 19•4 years ago
|
||
Similar to bug 1761407 we rated the impact of this issue as "low" because it is more of a site vandalism problem than affecting major functionality.
Updated•4 years ago
|
Updated•2 years ago
|
Description
•