Input validation #1

Closed
opened 2026-06-01 04:11:30 +00:00 by h · 17 comments
Owner

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.

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.
Contributor

What exactly would be the expected input? Just a youtube URL?

What exactly would be the expected input? Just a youtube URL?
Author
Owner

Line 14 in 2ff8b70
await (await fetch(`https://www.youtube.com/@${channelName}`)).text(),


The expected input is a YouTube account username

https://git.h.wer.ee/h/ytrss/src/commit/2ff8b700980533cfac23dd7a685dd260e52c6c8a/index.js#L14 The expected input is a YouTube account username
Contributor

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

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
Author
Owner

Honestly, that looks extremely hard to validate, would consider anything not using common ASCII characters to be unsupported at this time

Honestly, that looks extremely hard to validate, would consider anything not using common ASCII characters to be unsupported at this time
Contributor

Fair enough, do you agree with the rest of my intent though? (3-30 alphanumeric [plus _-.·] characters)

Fair enough, do you agree with the rest of my intent though? (3-30 alphanumeric [plus `_-.·`] characters)
Author
Owner

@Firepup650 wrote in #1 (comment):

Fair enough, do you agree with the rest of my intent though? (3-30 alphanumeric [plus _-.·] characters)

Sounds good!

@Firepup650 wrote in https://git.h.wer.ee/h/ytrss/issues/1#issuecomment-49: > Fair enough, do you agree with the rest of my intent though? (3-30 alphanumeric [plus `_-.·`] characters) Sounds good!
Contributor

What should resolve_ytid return for bad ids? should we just bail with an error or return nothig or how should we handle this?

What should `resolve_ytid` return for bad ids? should we just bail with an error or return nothig or how should we handle this?
Author
Owner

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

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
Contributor

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:

app.use(function(error, req, res, next) {
  console.log(error);
  res.status(500).render(dir + "errors/500.ejs", { error });
});
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: ```javascript app.use(function(error, req, res, next) { console.log(error); res.status(500).render(dir + "errors/500.ejs", { error }); }); ```
Author
Owner

@Firepup650 wrote in #1 (comment):

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:

app.use(function(error, req, res, next) {
  console.log(error);
  res.status(500).render(dir + "errors/500.ejs", { error });
});

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

@Firepup650 wrote in https://git.h.wer.ee/h/ytrss/issues/1#issuecomment-53: > 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: > > ```javascript > app.use(function(error, req, res, next) { > console.log(error); > res.status(500).render(dir + "errors/500.ejs", { error }); > }); > ``` 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
Contributor

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?

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?
Author
Owner

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

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
Contributor

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?

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?
Author
Owner

Honestly, a 400 response seems appropriate for a validation failure

Honestly, ![a 400 response](https://http.cat/400) seems appropriate for a validation failure
Contributor

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)

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)
Author
Owner

@Firepup650 wrote in #1 (comment):

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)

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.

@Firepup650 wrote in https://git.h.wer.ee/h/ytrss/issues/1#issuecomment-59: > 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) 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.
Contributor

Fair enough.

Fair enough.
h closed this issue 2026-07-15 23:48:03 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
h/ytrss#1
No description provided.