Skip to content
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

Provide methods to obtain or limit URL length #1017

Open
raffomania opened this issue Jan 27, 2025 · 0 comments
Open

Provide methods to obtain or limit URL length #1017

raffomania opened this issue Jan 27, 2025 · 0 comments

Comments

@raffomania
Copy link

raffomania commented Jan 27, 2025

I'd like to request your thoughts on the following feature idea.

Context

In my ActivityPub web application, I'm parsing untrusted user input as URLs and then storing them in the database. To reject URLs that are too long, I use the garde crate:

// The form accepted by HTTP endpoints
#[derive(Validate)]
pub struct CreateActivityPubUser {
    #[garde(length(max = 2048), url)]
    pub activity_pub_id: String,
    // ...
}

The Problem

To make working with form structs more ergonomic, I'd like to use an Url value instead of a String. However, there's no way to inspect an Url and check its length, making it impossible to validate an already parsed Url.

Ideal Solution

Provide method on Url structs to obtain some measure of their length. The concrete unit being counted is not important, as long as it allows determining whether an Url exceeds some upper bound.
This would allow garde and other crates to validate Url structs directly:

// The form accepted by HTTP endpoints
#[derive(Validate)]
pub struct CreateActivityPubUser {
    #[garde(length(max = 2048))]
    pub activity_pub_id: Url,
    // ...
}

Alternative Solutions

Either a method to truncate a given URL to a certain length, or a way to restrict URL length while parsing would work as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant