Skip to content

Strip NUL characters from tagged#7291

Open
emilghittasv wants to merge 1 commit into
mozilla:mainfrom
emilghittasv:fix-null-bytes-in-tagged
Open

Strip NUL characters from tagged#7291
emilghittasv wants to merge 1 commit into
mozilla:mainfrom
emilghittasv:fix-null-bytes-in-tagged

Conversation

@emilghittasv

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread kitsune/questions/views.py Outdated
@emilghittasv emilghittasv force-pushed the fix-null-bytes-in-tagged branch 2 times, most recently from f1a59d7 to d479d87 Compare March 18, 2026 21:45

@akatsoulas akatsoulas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+wc

Comment thread kitsune/questions/views.py Outdated
Comment thread kitsune/questions/views.py Outdated
Comment thread kitsune/flagit/views.py Outdated
@emilghittasv emilghittasv force-pushed the fix-null-bytes-in-tagged branch from d479d87 to 7562598 Compare May 21, 2026 15:37

if not (
((request.method == "GET") and (watch_secret := request.GET.get("watch", None)))
((request.method == "GET") and (watch_secret := strip_nul_bytes(request.GET.get("watch", None))))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is not needed in the get() method. It's the default value

@cache_page(60 * 60 * 24) # One day.
def api(request):
s = request.GET.get("s", None)
s = strip_nul_bytes(request.GET.get("s", None))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is not needed in the get() method. It's the default value

Comment thread kitsune/users/api.py
"""An API to provide auto-complete data for user names."""
term = request.GET.get("term", "")
query = request.GET.get("query", "")
term = strip_nul_bytes(request.GET.get("term", ""))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some calls like this one, pass an empty string as a default value and others rely on None. We should be consistent

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good way to enforce this is by adding a str -> str contract in the signature of the function

Comment thread kitsune/sumo/utils.py
pass


def strip_nul_bytes(value):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern with this PR is that we need to remember to sanitize which leaves a lot of room for errors. For example this PR already missed a call I believe in wiki/views. I suspect this will happen often. We could use a middleware for GET and POST requests only.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@escattone thoughts on this?

@akatsoulas

Copy link
Copy Markdown
Collaborator

@escattone can you take a look on this ?

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 this pull request may close these issues.

2 participants