cross-posted from: https://programming.dev/post/10497245

Hi,

For websites I’ve always restricted username to use Apostrophe ' and " and some times even space . If a website necessitate special character then I prefer to create an additional DB field ~DisplayName.

It’s easier to forbid the use of Apostrophe, otherwise you will have to escape also your search query to match what has been recorded in the DB.

On the topic I’ve this https://security.stackexchange.com/questions/202902/is-single-quote-filtering-nonsense

But if you have better documentation feel free to share :)

Thanks

  • sugar_in_your_tea
    link
    fedilink
    arrow-up
    2
    ·
    9 months ago

    We’re in a community focused on cyber security, and the question linked this stack exchange thread, which is explicitly about SQL injection. From that article:

    To block single quotes in all input is madness. This breaks functionality of the application and isn’t even the correct solution against SQL injection.

    The context is SQL injection, which typically is a backend thing. That’s why I talked about BE vs FE. You could instead say “DB layer” vs “presentation layer” if you prefer.

    But my point is that removing single quotes in the context of cyber security completely misses the point. Only remove single quotes (or any other character) if it makes sense for your application use case, not for some vague sense of “security.” If allowing single quotes causes a security vulnerability, your code is wrong even if you disallow single quotes.