You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Allow more characters in device IDs
This commit is contained in:
@@ -70,13 +70,35 @@ impl Device {
|
||||
}
|
||||
}
|
||||
|
||||
const fn valid_device_chars(c: char) -> bool {
|
||||
// This matches the regex in the policy
|
||||
c.is_ascii_alphanumeric()
|
||||
|| c == '.'
|
||||
|| c == '_'
|
||||
|| c == '~'
|
||||
|| c == '!'
|
||||
|| c == '$'
|
||||
|| c == '&'
|
||||
|| c == '\''
|
||||
|| c == '('
|
||||
|| c == ')'
|
||||
|| c == '*'
|
||||
|| c == '+'
|
||||
|| c == ','
|
||||
|| c == ';'
|
||||
|| c == '='
|
||||
|| c == ':'
|
||||
|| c == '@'
|
||||
|| c == '/'
|
||||
|| c == '-'
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Device {
|
||||
type Error = InvalidDeviceID;
|
||||
|
||||
/// Create a [`Device`] out of an ID, validating the ID has the right shape
|
||||
fn try_from(id: String) -> Result<Self, Self::Error> {
|
||||
// This matches the regex in the policy
|
||||
if !id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') {
|
||||
if !id.chars().all(valid_device_chars) {
|
||||
return Err(InvalidDeviceID::InvalidCharacters);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user