Skip to content
CSRF Disclosed report Beginner

CSRF When accepting an answer as the solution to a question

The endpoint that marks an answer as the solution to a question accepts GET requests, which Django does not protect against CSRF. An attacker could craft a link that, when visited by a logged-in question creator, silently marks an attacker-chosen answer as the solution.

roldanbrandon62 Follow

Originally disclosed on Mozilla

  • Fixed in 2 months
  • Paid in 14 days
  • Disclosed after 2 months

SUMMARY

Hi. While reading the code, i found out an interesting endpoint /questions/<questionID>/solve/<answerID>, This endpoint, allows the creator of a question to mark an answer as the solution. What makes this interesting is that it is done in a get request, and in django, get requests are not protected by csrf making it vulnerable to csrf attacks It calls the function solve, and this function doesnt have the require_POST middleware, nor does it check if the request is a post request in the function.

I havent really tested it yet since the production site is still down, but theoretically, it is possible.

This is the function handling the endpoint

Python
def solve(request, question_id, answer_id):
    """Accept an answer as the solution to the question."""

    question = get_object_or_404(Question, pk=question_id, is_spam=False)

    # It is possible this was clicked from the email.
    if not request.user.is_authenticated:
        watch_secret = request.GET.get("watch", None)
        try:
            watch = Watch.objects.get(
                secret=watch_secret, event_type="question reply", user=question.creator
            )
            # Create a new secret.
            distinguishable_letters = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXYZ"
            new_secret = "".join(random.choice(distinguishable_letters) for x in range(10))
            watch.update(secret=new_secret)
            request.user = question.creator
        except Watch.DoesNotExist:
            # This user is neither authenticated nor using the correct secret
            return HttpResponseForbidden()

    answer = get_object_or_404(Answer, pk=answer_id, is_spam=False)

    if not question.allows_solve(request.user):
        raise PermissionDenied

    if question.creator != request.user and not request.user.has_perm("questions.change_solution"):
        return HttpResponseForbidden()

    if not question.solution:
        question.set_solution(answer, request.user)

        messages.add_message(request, messages.SUCCESS, _("Thank you for choosing a solution!"))
    else:
        # The question was already solved.
        messages.add_message(request, messages.ERROR, _("This question already has a solution."))

    return HttpResponseRedirect(question.get_absolute_url())

The original report as published on Mozilla's Bugzilla, by roldanbrandon62. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The endpoint performs a state-changing action (marking a solution) via a GET request, and the handler lacks the require_POST decorator or any POST check, so Django's CSRF protection does not apply.

Impact

An attacker could cause a logged-in question creator to mark an arbitrary answer as the solution without their consent, potentially disrupting the question's content or misleading other users.

What the attacker needed

Victim is logged in as question creator; victim visits attacker-controlled link

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you log into a website, your browser sends a cookie with every request to that site. If a website changes something important using a simple link (a GET request), another site can trick your browser into sending that request without you knowing. This is called cross-site request forgery (CSRF). Here, the action of marking an answer as the solution could be triggered just by visiting a link, so an attacker could make you do it unintentionally.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

More by roldanbrandon62

View all

5 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.