142

I'm getting this error when connecting to a web server on port 6666 (http://myserver:6666/):

Error 312 (net::ERR_UNSAFE_PORT): Unknown error.

Is there an easy way to resolve this without rebuilding Chrome from source?

1

7 Answers 7

100

On Windows:

Right Click on Chrome shortcut >> Properties >>

Then Append --explicitly-allowed-ports=xxx to shortcut target

Example:

C:\Documents and Settings\User\Local Settings\Application Data\Google\Chrome\Application\chrome.exe --explicitly-allowed-ports=6666

Resource from here

7
  • 3
    I missed this answer, thanks. I opened a separate question to understand which ports are safe/blocked by default: superuser.com/questions/188058/…
    – ripper234
    Commented Sep 13, 2010 at 12:36
  • 4
    This answer is excellent... for Windows. It won't solve the problem for (for example) Mac.
    – Chris R
    Commented May 3, 2012 at 17:23
  • @ChrisR: Why? Does the --explicitly-allowed-ports switch not exist for Mac?
    – Dennis
    Commented May 3, 2012 at 17:35
  • 3
    Adding command line flags on the mac is a pain in the ass; if you add them to the app bundle they often get nuked in upgrades.
    – Chris R
    Commented May 3, 2012 at 17:39
  • 1
    @ChrisR: You should consider adding this to your question.
    – Dennis
    Commented May 3, 2012 at 17:44
33

You can explicitly allow ports just like the other answers state, but for most cases the problem is easier to solve by just not using the restricted ports:

const int kRestrictedPorts[] = {
    1,      // tcpmux
    7,      // echo
    9,      // discard
    11,     // systat
    13,     // daytime
    15,     // netstat
    17,     // qotd
    19,     // chargen
    20,     // ftp data
    21,     // ftp access
    22,     // ssh
    23,     // telnet
    25,     // smtp
    37,     // time
    42,     // name
    43,     // nicname
    53,     // domain
    69,     // tftp
    77,     // priv-rjs
    79,     // finger
    87,     // ttylink
    95,     // supdup
    101,    // hostriame
    102,    // iso-tsap
    103,    // gppitnp
    104,    // acr-nema
    109,    // pop2
    110,    // pop3
    111,    // sunrpc
    113,    // auth
    115,    // sftp
    117,    // uucp-path
    119,    // nntp
    123,    // NTP
    135,    // loc-srv /epmap
    137,    // netbios
    139,    // netbios
    143,    // imap2
    161,    // snmp
    179,    // BGP
    389,    // ldap
    427,    // SLP (Also used by Apple Filing Protocol)
    465,    // smtp+ssl
    512,    // print / exec
    513,    // login
    514,    // shell
    515,    // printer
    526,    // tempo
    530,    // courier
    531,    // chat
    532,    // netnews
    540,    // uucp
    548,    // AFP (Apple Filing Protocol)
    554,    // rtsp
    556,    // remotefs
    563,    // nntp+ssl
    587,    // smtp (rfc6409)
    601,    // syslog-conn (rfc3195)
    636,    // ldap+ssl
    989,    // ftps-data
    990,    // ftps
    993,    // ldap+ssl
    995,    // pop3+ssl
    1719,   // h323gatestat
    1720,   // h323hostcall
    1723,   // pptp
    2049,   // nfs
    3659,   // apple-sasl / PasswordServer
    4045,   // lockd
    5060,   // sip
    5061,   // sips
    6000,   // X11
    6566,   // sane-port
    6665,   // Alternate IRC [Apple addition]
    6666,   // Alternate IRC [Apple addition]
    6667,   // Standard IRC [Apple addition]
    6668,   // Alternate IRC [Apple addition]
    6669,   // Alternate IRC [Apple addition]
    6697,   // IRC + TLS
    10080,  // Amanda
};

Source

So instead of 6666 you could use 6060 and you wouldn't have this problem.

1
  • 2
    For my case, this was a perfect solution. Thanks for suggesting it! Commented May 12, 2022 at 6:41
22

You may be able to turn this off in Google Chrome, but you do so at your own risk. There is actually a good security reason why Chrome blocks these ports: Basically you open your browser up to being an open proxy for attackers to use to attack other services on your network.

For more information: Why does Chrome consider some ports unsafe?

5
  • 21
    Why just making an HTTP request on a non standard port it is said to "open" the browser to being an open proxy to attack services in local network? Open how??
    – red-o-alf
    Commented Jul 22, 2016 at 19:59
  • If it is left unchecked then any malicious code can make request to URLs with arbitrary ports. It might not be an optimal solution but by blocking other ports you are only leaving attackers with 80 & 443 to exploit.
    – Willa
    Commented Jan 23, 2017 at 14:39
  • the referenced link is now dead Commented Jun 13, 2017 at 15:41
  • Link is now dead. Wayback Machine: web.archive.org/web/20170216040700/https://jazzy.id.au/2012/08/… (suggested edit)
    – Nulano
    Commented Jun 26, 2017 at 17:54
  • 1
    Link is now fixed on the server (server had an incorrectly configured timezone causing it to serve the blog post at the wrong date). Commented Jun 27, 2017 at 13:47
10

On Mac you can create an app launching Chrome with parameters mentioned in other answers using Automator built-in Apple application:

  1. Launch Automator

  2. As "Type of document" choose "Application"

  3. Add action "Run shell script"

  4. Replace placeholder cat script in this action with:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --explicitly-allowed-ports=5000,6000,7000

  1. Save the created app as something like "Google Chrome with allowed unsafe ports" in your Application folder

  2. Use this new app instead of Google Chrome directly

  3. (optional) Replace default icon of the created "app" - Automator's robot - with Chrome's using this method (note: upvote that answer if you like it!)

Source: http://cubewot.de/node/266

image

1
  • This picture does not have the full path. It is automating the execution of a directory.
    – ojblass
    Commented Sep 19, 2018 at 4:27
7

As subanki said, you've got to add the -explicitly-allowed-ports option to your Chrome startup command.

In Ubuntu you can do this (as root) by editing the "google-chrome" script under your Chrome installation folder

You can get the directory by typing:

ls -la /usr/bin | grep chrome

Then, edit the "google-chrome" file adding the mentioned switch to the EXEC line:

exec -a "$0" "$HERE/chrome" "-explicitly-allowed-ports=6000" "$@"

Just change "6000" with the comma separated values you might need (example: -explicitly-allowed-ports=5000,6000,7000)

NOTE: for UNIX, the switch does NOT start with "--", it does with a single "-"

1
  • 2
    FWIW, the -- on unix is a GNU-specific convention. It's emulated by many, but not all unix utilities.
    – jpaugh
    Commented Apr 18, 2019 at 14:54
7

For Mac:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --explicitly-allowed-ports=5000,6000,7000

for ports 5000, 6000, and 7000.

0

Here is the correct answer for those of you who are developers using node.js as a web server: change the port you are using to host your web pages.

For example
if you typed into command line node index.js & pressed enter,
if it started running on port 22 for 80 http request,
when you visit the website at port 22,
the chrome browser with throw this error page.,br> keyword UNSAFE PORT means port needs to match the content.

You must log in to answer this question.

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