Skip to content

Provide methods to obtain or limit URL length #1017

Open
@raffomania

Description

@raffomania

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions