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

Disallowed underscores at the end of usernames aren't detected #543

Closed
matheus23 opened this issue Jul 20, 2021 · 4 comments
Closed

Disallowed underscores at the end of usernames aren't detected #543

matheus23 opened this issue Jul 20, 2021 · 4 comments
Labels
🐛 bug Something isn't working

Comments

@matheus23
Copy link
Member

Summary

Usernames like foo_ are invalid (because they can't be used in domains like foo_,files.fission.name), but these cases aren't caught by the code.

Impact

Not sure. Probably a bad error message in the CLI on account creation (with a name that has a trailing underscore).

Solution

Add a check for a trailing underscore to isValid.

Detail

Missing a note endsWithUnderscore in the preds list in isValid:

-- | Confirm that a raw is valid
isValid :: Text -> Bool
isValid txt =
  all (== True) preds
  where
    preds :: [Bool]
    preds = [ okChars
            , not blank
            , not startsWithHyphen
            , not endsWithHyphen
            , not startsWithUnderscore
            , not inBlocklist
            ]

    blank = Text.null txt

    inBlocklist = elem txt Security.blocklist
    okChars     = Text.all isURLChar txt

    startsWithHyphen = Text.isPrefixOf "-" txt
    endsWithHyphen   = Text.isSuffixOf "-" txt

    startsWithUnderscore = Text.isPrefixOf "_" txt

isURLChar :: Char -> Bool
isURLChar c =
     Char.isAsciiLower c
  || Char.isDigit      c
  || c == '-'
  || c == '_'
@matheus23 matheus23 added the 🐛 bug Something isn't working label Jul 20, 2021
@expede
Copy link
Member

expede commented Aug 11, 2021

@matheus23 I don't think that this is a bug. Here's some (manual) examples with multiple trailing underscores:

❯ nslookup -q=TXT foo_.bar_.runfission.net
Server:		192.168.0.1
Address:	192.168.0.1#53

Non-authoritative answer:
foo_.bar_.runfission.net	text = "Testing by @expede"
❯ nslookup -q=TXT foo_____.runfission.net
Server:		192.168.0.1
Address:	192.168.0.1#53

Non-authoritative answer:
foo_____.runfission.net	text = "Another test by @expede"

We've disallowed underscores at the beginning of usernames, because those are often reserved words in many systems.

@expede
Copy link
Member

expede commented Aug 11, 2021

For context, I believe that this was opened in relation to https://github.com/fission-suite/webnative/issues/259

If underscores at the end of names are invalid, then we're not checking that both in the server and webnative.
Easy enough to fix though :)

I misspoke for underscores. Underscores are actually valid at the beginning and end. We used to disallow beginning and end underscores to avoid confusion around things like _dnslink, which is also on the blocklist, but starting with _ often signifies a special/internal subdomain. We had someone complain that they use a name that ends in an underscore elsewhere on the internet, so we lifted the restriction for the end specifically. No change required on the server unless we want to lift the restriction on the front as well.

@matheus23
Copy link
Member Author

I guess we can just close both issues? As far as I understand, there's nothing wrong with username validation, right?

@expede
Copy link
Member

expede commented Aug 11, 2021

On the backend at least, yeah. I don't think I can reproduce the FE issues, but I'll ping Jeff about that on the original issue

@expede expede closed this as completed Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants