Skip to content

Commit b63622f

Browse files
author
yajian.ke
committed
[fix]修复了自定义权限检验器无法识别携带数字id的patch,put请求,而自动放行的安全漏洞
1 parent 71c0d19 commit b63622f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

utils/permissions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def has_permission(self, request, view):
4747
raise PermissionDenied("用户未激活")
4848
# 获取请求路径, 并进行处理
4949
path = request.path
50-
# 如果请求的路径最后一部分是uuid,则去掉uuid部分
50+
# 如果请求的路径最后一部分是uuid或者数字,则去掉最后一部分(patch和put请求)
5151
uuid_pattern = re.compile(r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
52+
number_pattern = re.compile(r"^\d+$")
5253
path_parts = path.rstrip("/").split("/")
53-
if uuid_pattern.match(path_parts[-1]):
54+
if uuid_pattern.match(path_parts[-1]) or number_pattern.match(path_parts[-1]):
5455
if path_parts:
5556
path = "/".join(path_parts[:-1]) + "/"
5657
else:

0 commit comments

Comments
 (0)