-
Notifications
You must be signed in to change notification settings - Fork 38
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
Improve URL validation and centralise client and server validators #164
Conversation
src/server/models/url.ts
Outdated
// Disable long url checks for localstack in development. | ||
...(!DEV_ENV ? { isUrl: true } : {}), | ||
urlCheck(url: string) { | ||
if (!isValidUrl(url, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean someone will be able to save the whitelisted localhost URL in production?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, users will not be able to using as we are enforcing https during link creation and edits. But I get the gist here. I will convert the whitelist to a dev-only whitelist. Subsequently, if there is a need for a global whitelist in the future, it should be quite easy to add in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a good first step towards standardising URL validation. can we guarantee there is no change in behavior?
one possible improvement in the future would be to replace the useWhitelist
flag with dependency injection, because the setting is specific to the application environment, and the onus is on the caller to know whether to use a whitelist or not.
I have updated my code such that whitelist is only used when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Problem
This PR is a follow-up to #149. Previously, the check for https was disabled in development, as localstack endpoints are not valid urls.
And as suggested by @liangyuanruo, I have centralised the common validators used by our client and server sides.
Solution
isUrl
check to our customised checks using thevalidator
library. After which, I whitelist the endpoint used by localstack (http://localhost:4572).isValidUrl
andisHttps
, to indicate whether to take into account whitelisted hostnames when running the validation.Improvements:
src/shared/util/validation.ts
.