launchbadge / realworld-axum-sqlx

A Rust implementation of the Realworld demo app spec using Axum and SQLx.
GNU Affero General Public License v3.0
813 stars 82 forks source link

Missing input validations #3

Open abonander opened 2 years ago

abonander commented 2 years ago

As pointed out by /u/LucasMathWalker on Reddit: https://www.reddit.com/r/rust/comments/shetb1/show_rrust_a_rust_implementation_of_the_realworld/hv42wuo/

Text inputs in various routes are not properly validated. That's an oversight on my part. Were I designing these routes from scratch I would have considered it, but the Realworld spec is silent on input validation so I wasn't thinking about it.

Where variables are given, pick reasonable values for the context but don't assume they are the same values between routes:

abonander commented 2 years ago

It would be interesting to use https://github.com/Keats/validator, it's almost exactly what I was thinking when I mentioned an input validator framework in the Reddit thread.

The only thing it's missing, IMO, is enforcement of validation via typestate, so you can't forget to apply validation before you access the struct fields. I've made the suggestion there: https://github.com/Keats/validator/issues/185