[英]Django + Postgres: A string literal cannot contain NUL (0x00) characters
[英]Django url arg cannot contain NUL (0x00) characters
我目前正在测试我们网站的安全漏洞,而我本人的安全背景非常有限。
运行以下请求时:
http://127.0.0.1:8000/stuff/?template=%2Fe%00
我看到错误(下面是完整的堆栈跟踪):
Exception Type: ValueError at /stuff/
Exception Value: A string literal cannot contain NUL (0x00) characters.
验证网址args似乎是一个问题,并且不应允许使用字符0x00(空)。 我相当确定在Google的格鲁耶尔(gruyere)中我看到一些字符应该转义,但转为null似乎很奇怪。
我当然可以尝试/除了/code/stuff/views.py
第92 /code/stuff/views.py
,但这无疑会在其他地方出现。
因此,我的问题是:
堆栈跟踪:
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
97. return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/list.py" in get
157. context = self.get_context_data()
File "/code/stuff/views.py" in get_context_data
92. context = super(StuffListView, self).get_context_data(**kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/list.py" in get_context_data
119. paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/list.py" in paginate_queryset
69. page = paginator.page(page_number)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in page
70. number = self.validate_number(number)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in validate_number
48. if number > self.num_pages:
File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py" in __get__
80. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in num_pages
97. if self.count == 0 and not self.allow_empty_first_page:
File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py" in __get__
80. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py" in count
91. return c()
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in count
392. return self.query.get_count(using=self.db)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_count
504. number = obj.get_aggregation(using, ['__count'])['__count']
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/query.py" in get_aggregation
489. result = compiler.execute_sql(SINGLE)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1100. cursor.execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
99. return super().execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
67. return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
76. return executor(sql, params, many, context)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
84. return self.cursor.execute(sql, params)
Exception Type: ValueError at /stuff/
Exception Value: A string literal cannot contain NUL (0x00) characters.
基于追溯,问题不是URL参数不能包含%00
,而是在通过Paginator
将其传递到正在使用的数据库时,数据库驱动程序正在抱怨这些事情。
根据错误判断,您可能正在使用Postgres。 (请参阅以下相关问题: Django + Postgres:字符串文字不能包含NUL(0x00)字符 )
如果愿意,您可以设置一个中间件来拒绝任何包含%00
请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.