Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrestricted deserialization #867

Closed
MisakiKata opened this issue Jun 19, 2020 · 5 comments
Closed

Unrestricted deserialization #867

MisakiKata opened this issue Jun 19, 2020 · 5 comments
Assignees
Labels
Bug Errors or not functioning as designed

Comments

@MisakiKata
Copy link

tendenci\apps\helpdesk\views\staff.py
There is no limit to the input of the pickle called, there will be problems

def ticket_list(request):
    context = {}
    ......
    if request.GET.get('saved_query', None):
            from_saved_query = True
            try:
                saved_query = SavedSearch.objects.get(pk=request.GET.get('saved_query'))
            except SavedSearch.DoesNotExist:
                return HttpResponseRedirect(reverse('helpdesk_list'))
            if not (saved_query.shared or saved_query.user == request.user):
                return HttpResponseRedirect(reverse('helpdesk_list'))

            import pickle
            from base64 import b64decode
            query_params = pickle.loads(b64decode(str(saved_query.query).encode()))
        elif not (  'queue' in request.GET
                or  'assigned_to' in request.GET
                or  'status' in request.GET
                or  'q' in request.GET
                or  'sort' in request.GET
                or  'sortreverse' in request.GET
                    ):

query field

    import pickle
    from base64 import b64encode
    urlsafe_query = b64encode(pickle.dumps(query_params)).decode()

Find the request to save the field from the form

<form method='post' action='{% url 'helpdesk_savequery' %}'>
    <input type='hidden' name='query_encoded' value='{{ urlsafe_query }}' />
    <dl>
        <dt><label for='id_title'>{% trans "Query Name" %}</label></dt>
        <dd><input type='text' name='title' id='id_title' /></dd>
        <dd class='form_help_text'>{% trans "This name appears in the drop-down list of saved queries. If you share your query, other users will see this name, so choose something clear and descriptive!" %}</dd>

        <dt><label for='id_shared'>{% trans "Shared?" %}</label></dt>
        <dd><input type='checkbox' name='shared' id='id_shared' /> {% trans "Yes, share this query with other users." %}</dd>
        <dd class='form_help_text'>{% trans "If you share this query, it will be visible by <em>all</em> other logged-in users." %}</dd>

    </dl>

    <div class='buttons'>
        <input class="btn btn-primary" type='submit' value='{% trans "Save Query" %}'>
    </div>

    {% csrf_token %}</form>

Save the field as follows

def save_query(request):
    title = request.POST.get('title', None)
    shared = request.POST.get('shared', False) in ['on', 'True', True, 'TRUE']
    query_encoded = request.POST.get('query_encoded', None)

    if not title or not query_encoded:
        return HttpResponseRedirect(reverse('helpdesk_list'))

    query = SavedSearch(title=title, shared=shared, query=query_encoded, user=request.user)
    query.save()

This place is to save the serialized value to the template, and then the front-end template uses the encoded value request, and the background is deserialized.
eg: https://docs.python.org/3/library/pickle.html

@jennyq
Copy link
Member

jennyq commented Jun 19, 2020

Thanks @MisakiKata! Looks like the pickled query object needs to be converted to json object.

@MisakiKata
Copy link
Author

@jennyq You're welcome, there is no problem using json.

@eschipul eschipul added the Bug Errors or not functioning as designed label Jul 13, 2020
@galaktipus
Copy link

Is there any commit available that closes the issue?

@jennyq
Copy link
Member

jennyq commented Aug 24, 2020

Hey @galaktipus, not yet. You're welcome to submit a pull request if you'd like. Otherwise, I'll get to it when I get the chance.

@jennyq jennyq closed this as completed in 783d0cc Dec 4, 2020
@jennyq
Copy link
Member

jennyq commented Dec 4, 2020

Resolved 783d0cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Errors or not functioning as designed
Projects
None yet
Development

No branches or pull requests

4 participants