question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom protocols and defining their origin

See original GitHub issue

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: https://github.com/cyu/rack-cors/blob/42ebe6caa8e85ffa9c8a171bda668ba1acc7a5e6/lib/rack/cors.rb#L256

            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!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rafamanzocommented, Jul 25, 2019

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?

0reactions
cyucommented, Sep 11, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Protocol Handling — How To | by Tal Martsiano
The following article explains how to handle custom protocol in different operation systems and launching applications using custom browser ...
Read more >
Creating a custom protocol - Forcepoint
A custom protocol can be assigned the same name as a pre-defined protocol, in order to extend the number of IP addresses or...
Read more >
Creating a Custom Protocol [Support] - Cisco Systems
To define a custom protocol, perform the following steps. Enables privileged EXEC mode.
Read more >
Protocols — The Swift Programming Language (Swift 5.7)
Custom types state that they adopt a particular protocol by placing the protocol's name after the type's name, separated by a colon, as...
Read more >
Creating Custom Protocols for your Website - YouTube
Have you ever wanted to create a custom link with your own invented protocol instead of "http" or "https"?Well with very little JavaScript ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found