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

Arguments containing colons can be mis-cached #32

Closed
akx opened this issue Jun 11, 2019 · 0 comments · Fixed by #33
Closed

Arguments containing colons can be mis-cached #32

akx opened this issue Jun 11, 2019 · 0 comments · Fixed by #33

Comments

@akx
Copy link
Contributor

akx commented Jun 11, 2019

Since the default key construction uses a colon (:) to separate raw string values, strings arguments with colons in them can lead to mis-caching.

(If an argument is user input, this could theoretically be a security issue allowing an user to access the "wrong" object from the cache.)

POC – the assertion fails since only one call was made, since the cache key is a:b:c:bla for both invocations.

def test_colons():
    calls_made = []
    @cache_memoize(10)
    def fun(a, b, k="bla"):
        calls_made.append((a, b, k))
        return (a, b, k)

    fun('a:b', 'c')
    fun('a', 'b:c')
    assert len(calls_made) == 2
akx added a commit to valohai/django-cache-memoize that referenced this issue Jun 11, 2019
The usage of quote() is inspired by Django's own `make_template_fragment_key`.

Fixes peterbe#32
akx added a commit to valohai/django-cache-memoize that referenced this issue Jun 12, 2019
The usage of quote() is inspired by Django's own `make_template_fragment_key`.

Fixes peterbe#32
peterbe pushed a commit that referenced this issue Jun 18, 2019
* Split tests a bit

* Fix mis-caching of arguments containing colons

The usage of quote() is inspired by Django's own `make_template_fragment_key`.

Fixes #32

* Travis: use xenial dist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant