Yes, you can trim or sanitize the input of user traits in Ory Kratos. This can be done by using regular expressions in the identity schema. Here's how you can approach this: 1. For usernames or traits that need to satisfy specific patterns (e.g., only alphanumeric characters), you can add regular expressions to the identity schema. 2. To sanitize usernames coming from third-party OIDC providers like Google or GitHub, you can write [JSONnet](
https://jsonnet.org) scripts. This approach allows you to ensure that the user input meets your specific requirements before it's stored in the identity traits. For more details on implementing this, you can refer to the [Ory Kratos Identity Schema Best Practices](
https://www.ory.sh/docs/kratos/manage-identities/best-practices#sanitize-usernamestraits) documentation. Remember that when working with identity schemas, it's important to keep your data lean and avoid storing sensitive information in the traits. The identity schema is visible to users and can be edited by them, so it's not suitable for storing sensitive internal data. [Ory Kratos Identity Schema Best Practices](
https://www.ory.sh/docs/kratos/manage-identities/best-practices) recommends: - Keeping the number of fields well below 15 - Not storing business logic in identities - Storing only profile data that is used across your system (e.g., usernames, email addresses, phone numbers, first names, and last names) For sensitive data that should be obfuscated from the user, use the
metadata_admin
field instead of storing it in the identity's traits.