9669 sanitize social auth usernames (#10549)

This commit is contained in:
Arthur Hanson 2022-10-05 08:50:47 -07:00 committed by GitHub
parent 689f11a573
commit cc00789d35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -498,7 +498,7 @@ for param in dir(configuration):
# Force usage of PostgreSQL's JSONB field for extra data # Force usage of PostgreSQL's JSONB field for extra data
SOCIAL_AUTH_JSONFIELD_ENABLED = True SOCIAL_AUTH_JSONFIELD_ENABLED = True
SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'netbox.users.utils.clean_username'
# #
# Django Prometheus # Django Prometheus

9
netbox/users/utils.py Normal file
View File

@ -0,0 +1,9 @@
from social_core.storage import NO_ASCII_REGEX, NO_SPECIAL_REGEX
def clean_username(value):
"""Clean username removing any unsupported character"""
value = NO_ASCII_REGEX.sub('', value)
value = NO_SPECIAL_REGEX.sub('', value)
value = value.replace(':', '')
return value