4

I'm trying to set up Windows 8.1 virtual machine through VirtualBox for testing a server running on my Mac (running Yosemite 10.10.3). VirtualBox sets up a the IP 10.0.2.2 to point to the host machine's localhost (where the server is running). To connect to a remote server with fairly specific CORS constraints, I need to point the guest OS's localhost to that address. I've tried adding an entry to the `C:\Windows\System32\Drivers\etc\hosts file, but while it works for other strings (like 'test' and 'foo') it doesn't work for localhost. I've run across a couple threads (https://serverfault.com/questions/4689/windows-7-localhost-name-resolution-is-handled-within-dns-itself-why) that obliquely refer to this functionality being moved into the DNS resolver, but not how to change it beyond saying that it's in group policy somewhere. Can anyone tell me how to set the localhost of the Windows 8.1 VM to a custom address?

5
  • Why is not something we can answer. We end users can only guess. MS might have good reason (e.g. performance gains?) but you would need to ask the MS engineers why the resolution of localhost to 127.1 is handled internally.
    – Hennes
    Commented Jul 8, 2015 at 16:59
  • @Hennes: The link I posted actually addresses the why pretty well (IPv6 transition), my question is how to get the old functionality given the change. Commented Jul 8, 2015 at 20:59
  • @AdamMcCormick did you ever manage to figure out how to do this? I am assuming there will be some (possibly undocumented) registry setting. I'm building a DNS resolver and I'm trying to work out if it's 100% safe for me to hard-code 127.0.0.1/::1 or there is some place I need to check for whether it has been changed. ftr I don't believe it's a good idea to change localhost, because many applications expect to be able to use it interchangeably with 127.0.0.1, e.g. some server application might bind explicitly to the IP address but its client app will use the name.
    – DaveRandom
    Commented Jan 29, 2018 at 15:01
  • @DaveRandom No, I never did. We had to change the CORS constraints. That said, It's been two and a half years so it may be resolved either for Window 8 or Windows 10 or both Commented Jan 29, 2018 at 18:32
  • @AdamMcCormick if there is a way to do it, no-one anywhere on the internet seems to know how, I'm just going to hard-code them and when someone reports it as a bug I will ask them how they did it :-P
    – DaveRandom
    Commented Jan 30, 2018 at 9:12

1 Answer 1

0

CORS relies on the following headers:

Request:

  • Origin

Response

  • Access-Control-Allow-Origin
  • Access-Control-Allow-Credentials

Add your subdomain to the Origin Request header, e.g. foo.bar.com Add the Access-Control-Allow-Origin Response header with your localhost value, e.g. localhost:9999. Add the Access-Control-Allow-Credentials Response header with a value of true.

References

2
  • Thanks for resurrecting this old thread, but the whole point was that I had no control of the CORS headers. Commented Oct 17, 2018 at 15:56
  • @AdamMcCormick I didn't realize that. In my case, I was working on Citrix and could not modify the hosts file as noted above. I also could not modify the Access-Control-Allow-Origin request header on the server. I realized that I could modify the Origin request header and the Access-Control-Allow-Origin response header via a chrome extension Commented Oct 17, 2018 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .