0

I have a button in my app that is supposed to open a link to the Rails app that seems to block access based on the request's referrer header.

When I use window.open('http://localhost/company?id=55', '_blank');, I get a 404 Not Found error, but when I paste the same URL in the browser tab, it opens just find. This suggests to me that the Rails app discriminates connections based on where they come from.

Is it possible to replace that window.open action with an XMLHttpRequest (or anything else) that would open my URL in a new tab, and will pass to it custom referer header?

verse
  • 236
  • 4
  • 9
  • You don't have to have a second argument by the way, because `_blank` is the default setting. – ntzm Oct 17 '14 at 20:35
  • What your doing should work where is your port number? – brso05 Oct 17 '14 at 20:42
  • http://localhost:8080/company?id=55 – brso05 Oct 17 '14 at 20:42
  • it's not a port issue. the same problem occurs when i move the rails app to the staging server. – verse Oct 17 '14 at 20:43
  • Do you have company servlet defined in your web.xml – brso05 Oct 17 '14 at 20:43
  • Also what does "the same problem occurs when i move the rails app to the staging server" that have to do with anything you should specify the port. – brso05 Oct 17 '14 at 20:44
  • @brso05, are you typing this on http://stackoverflow.com:80/ ? – artm Oct 17 '14 at 20:47
  • @brso05, unfortunately I don't know much about Rails, and how it does routing, but since the link works when I type the URL in the browser, I'm assuming that the controller is properly defined. – verse Oct 17 '14 at 20:47
  • @brso05, the staging server is using port 80 by default, so it can't be a port issue. – verse Oct 17 '14 at 20:49
  • 80 is the default port @artm – brso05 Oct 17 '14 at 20:49
  • 1
    Copy and pasting the url should be the same as window.open. – brso05 Oct 17 '14 at 20:51
  • @brso05, I know, but it isn't. The only thing that differs is the referrer header. And it's impossible to set a custom referrer header in `windown.open`, so I'm hoping to replicate it with `XMLHttpRequest` where it's possible to manually specify the headers. – verse Oct 17 '14 at 20:55
  • [Browser will not allow to override Referer for an `XMLHttpRequest`](http://stackoverflow.com/questions/8231366/changing-the-referrer-of-an-ajax-post) – artm Oct 17 '14 at 21:31

0 Answers0