Manoj
Manoj

Reputation: 5612

Play framework redirect to custom schemes

I want to redirect from my play framework server to a custom url scheme like file, but its not working

Server is running on 9000 and my endpoint takes redirect_uri param. Ex: http://localhost:9000/redirect?redirect_uri=file:///test

The browser is not redirected to if the url scheme is not http or https

route:

GET  /redirect  MyController.testRedirect(redirect_uri:String)

Controller:

import play.api.mvc._
import play.api.Logger

object MyController extends Controller {

  def testRedirect(redirect_uri: String) = Action {
    Logger.info(s"Opening: $redirect_uri")
    Redirect(redirect_uri)
  }
}

Upvotes: 0

Views: 78

Answers (1)

Anton Sarov
Anton Sarov

Reputation: 3748

This is not a problem of Play (or any other web framework for that matter). It is just how the browser is expected to work.

There are special restrictions applied on browsers when protocols like file: are involved. Of course you could argue that there shouldn't be any problem when the file is local but the general idea is to be on the safe side so this restriction is kind of global.

The are some pseudo-protocols like javascript: and data: which are permitted but nothing else should be allowed (except http: and https: of course).

You can read a bit more here:

https://code.google.com/archive/p/browsersec/wikis/Part2.wiki#Redirection_restrictions


If you want to return some file to your visitor you can just stream the data / provide a download option. Anything else won't work and should make you rethink your use case.

Upvotes: 1

Related Questions