Is there a way to restrict allowed uri characters in Expressjs. like set a variable of characters:
allowed_uri_chars = 'a-zA-Z0-9'; etc
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The most logical and easiest way to go would be to use a regex in some middleware:
Or, as the URL is already parsed by Express, but this is not exposed publicly, you may want to save one call to parse and rely on Express internals (which I wouldn’t advise):
This ensures that your pathname (for
http://example.com/foo/bar?id=1334, pathname would be/foo/bar) only contains letters, numbers, and slashes. It raises a 403 if not.