Skip to content

Custom protocols and defining their origin #100

@stefansundin

Description

@stefansundin

Hello there,

I am developing a chrome extension that talks to my website. The extension's origin is

chrome-extension://bjpcphhoenjjadogjjcelgjnnfgamiog

so I naturally defined

origins "chrome-extension://bjpcphhoenjjadogjjcelgjnnfgamiog"

in Rack::Cors' configuration.

But it didn't work. I got a 404 on the OPTIONS request. Weird, I though.

After some digging, I found this piece of code:

else Regexp.compile("^[a-z][a-z0-9.+-]*:\\\/\\\/#{Regexp.quote(n)}$")

            case n
            when Regexp,
                 /^https?:\/\//,
                 'file://'        then n
            when '*'              then @public_resources = true; n
            else                  Regexp.compile("^[a-z][a-z0-9.+-]*:\\\/\\\/#{Regexp.quote(n)}$")
            end

So unless your protocol is http, https, or file, you are not expected to specify the protocol? I tested it and using origins "bjpcphhoenjjadogjjcelgjnnfgamiog" worked.

What is the reason to even have that else clause? To me it would make sense to change that code to:

            @public_resources = true if n == '*'
            n

I guess I'm mostly confused of the origin of that code? It doesn't seem necessary, isn't explained in the docs as far as I could see, and it prevents you from using arbitrary protocols as strings.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions