Skip to content

Sanitize urls : privacy, read more and source (defense in depth) #1405

Description

@AmauriC

The idea is to be sure it's an url with an http(s):// scheme or internal url.

function sanitizeUrl(url) {
    try {
        const u = new URL(url, document.baseURI);

        if (
            u.protocol === 'http:' ||
            u.protocol === 'https:'
        ) {
            return u.href;
        }
    } catch(e) {}

    return '';
}

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions