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

fix:parse_username_domain 解析异常,报错信息泄漏,泄漏代码绝对路径 #1821

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/api/bkuser_core/api/login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@ def batch_query(self, request):
domain_username_map = defaultdict(list)

for x in username_list:
username, domain = parse_username_domain(x)
try:
username, domain = parse_username_domain(x)
except Exception:
raise error_codes.USERNAME_FORMAT_ERROR

if not domain:
# default domain
domain = ProfileCategory.objects.get_default().domain
Expand Down
17 changes: 15 additions & 2 deletions src/api/bkuser_core/api/web/password/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def post(self, request, *args, **kwargs):
# SaaS 修改密码页面需要登录态, 登录用户即operator
username = get_operator(request)
# 注意, 这里的username是带域的
username, domain = parse_username_domain(username)
try:
username, domain = parse_username_domain(username)
except Exception:
raise error_codes.USERNAME_FORMAT_ERROR

if not domain:
domain = ProfileCategory.objects.get(default=True).domain
instance = Profile.objects.get(username=username, domain=domain)
Expand Down Expand Up @@ -187,7 +191,11 @@ def get(self, request, *args, **kwargs):
else:
# 兼容登录态的change_password页面获取目录密码配置
username = get_operator(request)
username, domain = parse_username_domain(username)
try:
username, domain = parse_username_domain(username)
except Exception:
raise error_codes.USERNAME_FORMAT_ERROR

if not domain:
domain = ProfileCategory.objects.get(default=True).domain
try:
Expand Down Expand Up @@ -216,6 +224,7 @@ def post(self, request, *args, **kwargs):
try:
# 优先过滤username
username, domain = parse_username_domain(input_telephone)

if not domain:
domain = ProfileCategory.objects.get_default().domain
# filter过滤,判断是否存在,存在则仅有一个
Expand Down Expand Up @@ -248,6 +257,10 @@ def post(self, request, *args, **kwargs):
logger.exception("this telephone<%s> had bound to multi profiles", input_telephone)
raise error_codes.TELEPHONE_BOUND_TO_MULTI_PROFILE

except Exception:
logger.exception("failed to get profile by username<%s> because of username format error", input_telephone)
raise error_codes.USERNAME_FORMAT_ERROR

# 生成verification_code_token
verification_code_token = ResetPasswordVerificationCodeHandler().generate_reset_password_token(profile.id)
raw_telephone = profile.telephone
Expand Down
5 changes: 4 additions & 1 deletion src/api/bkuser_core/api/web/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ def get(self, request, *args, **kwargs):

data = slz.validated_data
username = data["username"]
try:
username, domain = parse_username_domain(username)
except Exception:
raise error_codes.USERNAME_FORMAT_ERROR

username, domain = parse_username_domain(username)
if not domain:
domain = ProfileCategory.objects.get(default=True).domain

Expand Down