Input validation #1
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Help Wanted
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
h/ytrss#1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, inputs are not validated. This makes it unsafe to expose a deployment of this project to the internet, to the extent that a deployment is likely to be abused if someone specifically targets it with knowledge of the underlying codebase.
What exactly would be the expected input? Just a youtube URL?
await (await fetch(`https://www.youtube.com/@${channelName}`)).text(),The expected input is a YouTube account username
fwiw, that's the channel "handle" not the channel name
based on https://support.google.com/youtube/answer/11585688?hl=en, probably will cap to 3-30 chars (ignoring the weird limits on different scripts), and do the "underscores/hypens/periods" rule, but I feel like "url-like" and "phone number-like" are a bit out-of-scope, unless you disagree
Honestly, that looks extremely hard to validate, would consider anything not using common ASCII characters to be unsupported at this time
Fair enough, do you agree with the rest of my intent though? (3-30 alphanumeric [plus
_-.·] characters)@Firepup650 wrote in #1 (comment):
Sounds good!
What should
resolve_ytidreturn for bad ids? should we just bail with an error or return nothig or how should we handle this?Honestly, an error would be best if and only if express handles that by returning an error on the HTTP request, rather than crashing the entire server
Since we're doing very little validation here, would it be worth it to have 404s/things like that also throw an error?
It's not hard to make express handle errors, in fact that's actually pretty easy.
Example from my site:
@Firepup650 wrote in #1 (comment):
if you want to implement such a thing, go for it, I guess!
would prefer it if different types of things caused different types of errors and resulted in different responses tbh
That shouldn't be hard either, we can do an if/then/elif check off the error message from the error object that gets passed to the error handler.
For things that fail input validation/404 on youtube, should we just send a 404, and a 500 for any unknown error?
would prefer errors that make sense, so a 404 for input validation failures wouldn't be ideal.
honestly, feel free to submit a PR; reviewing an actual implementation would be easier than reviewing ideas
What should we return then? It "should" be a 404 for channels on youtube that don't exist, and anything that fails input validation, by logic, does not exist, so I feel a 404 is correct as a reply, you know?
Honestly,
seems appropriate for a validation failure
I suppose that's fair, but then should we return a 400 for 404'd channels as well? It feels odd to treat validation failures as a 400, especially when the upstream service would give a 404 in reply instead (I think)
@Firepup650 wrote in #1 (comment):
Returning a 404 if we get an upstream 404 makes sense, sure, but if we're generating the response code ourselves based on our own validation failure, we should return something that reflects that, even if only for making debugging easier.
Fair enough.