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

Check for whitespace or newline characters in tokens #1305

Merged
merged 4 commits into from
May 13, 2019

Conversation

Chris-Johnston
Copy link
Collaborator

@Chris-Johnston Chris-Johnston commented May 10, 2019

This change checks for whitespace or newline characters in the token, and if there are any contained, will warn the user to trim their inputs first.

After discussion in the dnet channel, it was decided that the lib should not modify tokens. This PR was updated to instead validate them. (Previously was .Trim()ing them)

This change trims whitespace characters from the supplied token before it is used to log in. Users can encounter this accidentally if they read their token from a file that ends with a blank line.

Leading whitespace will make the token invalid. Trailing whitespace or \n (not \r\n) will also fail to log in. \r\n (CRLF) doesn't fail because of the line break style for http request headers.
…dation

Checks to see if a token contains any illegal characters, like whitespace or a newline. If it is, throws an ArgumentException warning the user that their token may be invalid.

I considered only checking the first and last character, but given that a token containing whitespace or a newline wouldn't work either I figured this made sense.
@Chris-Johnston Chris-Johnston changed the title Trim whitespace from tokens before logging in Check for whitespace or newline characters in token validation May 10, 2019
@Chris-Johnston Chris-Johnston changed the title Check for whitespace or newline characters in token validation Check for whitespace or newline characters in tokens May 10, 2019
These were leftover from a previous approach using an ImmutableHashSet
@foxbot foxbot merged commit bb61efa into discord-net:dev May 13, 2019
@Chris-Johnston Chris-Johnston deleted the feature/trim-tokens branch May 13, 2019 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants