Skip to content

Commit cc00789

Browse files
authored
9669 sanitize social auth usernames (#10549)
1 parent 689f11a commit cc00789

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

netbox/netbox/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def _setting(name, default=None):
498498

499499
# Force usage of PostgreSQL's JSONB field for extra data
500500
SOCIAL_AUTH_JSONFIELD_ENABLED = True
501-
501+
SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'netbox.users.utils.clean_username'
502502

503503
#
504504
# Django Prometheus

netbox/users/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from social_core.storage import NO_ASCII_REGEX, NO_SPECIAL_REGEX
2+
3+
4+
def clean_username(value):
5+
"""Clean username removing any unsupported character"""
6+
value = NO_ASCII_REGEX.sub('', value)
7+
value = NO_SPECIAL_REGEX.sub('', value)
8+
value = value.replace(':', '')
9+
return value

0 commit comments

Comments
 (0)