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

Custom protocols and defining their origin #100

Closed
stefansundin opened this issue Oct 19, 2015 · 5 comments
Closed

Custom protocols and defining their origin #100

stefansundin opened this issue Oct 19, 2015 · 5 comments

Comments

@stefansundin
Copy link

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!

@cyu
Copy link
Owner

cyu commented Jul 15, 2017

The most common usage of this middleware would be for normal HTTP and HTTPS usage, so configuration is optimized for that. The origin intent is to allow example.net to support both protocols (and not require them to be specified individually).

While I don't really have a strong preference for this style anymore, I'm inclined to leave it as it doesn't break backwards compatibility and your use case is still supported (as a regex).

@cyu cyu closed this as completed Jul 15, 2017
@rafamanzo
Copy link

I'm sorry to bring this up again after two years, but I have lost many hours on a similar problem, but now involving Ionic.

On iOS the Origin header is set to ionic://localhost (https://ionicframework.com/docs/faq/cors#ionic-webview-3-x-plugin-on-cordova).

Thus using origins 'ionic://localhost' led to errors when testing the app on iOS devices.

And I can confirm that origins 'localhost' works.

Is it worth to mention this behaviour for protocols different than http, https or file?

@aguynamedben
Copy link
Contributor

I'm developing a Chrome extension and this also sent me on a 3-hour spree until I found this ticket. Thanks for the workaround @stefansundin.

Documented + PR: #219

@cyu cyu reopened this Aug 4, 2021
@cyu
Copy link
Owner

cyu commented Aug 4, 2021

After reviewing @aguynamedben documentation PR, I realize I wasn't looking at this issue correctly so I'm re-opening this issue.

@cyu
Copy link
Owner

cyu commented Sep 11, 2022

This issue should be fixed with [#225], which is in 2.0.0.rc1

@cyu cyu closed this as completed Sep 11, 2022
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

4 participants