<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [111.0.1] Same Origin Policy ignores a different port number. in Discussions</title>
    <link>https://connect.mozilla.org/t5/discussions/111-0-1-same-origin-policy-ignores-a-different-port-number/m-p/49678#M17759</link>
    <description>&lt;P&gt;Do you have HTTPS-only mode enabled? If so, this sounds like &lt;A href="https://bugzilla.mozilla.org/show_bug.cgi?id=1751105" target="_blank"&gt;https://bugzilla.mozilla.org/show_bug.cgi?id=1751105&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2024 20:09:00 GMT</pubDate>
    <dc:creator>tanriol</dc:creator>
    <dc:date>2024-01-18T20:09:00Z</dc:date>
    <item>
      <title>[111.0.1] Same Origin Policy ignores a different port number.</title>
      <link>https://connect.mozilla.org/t5/discussions/111-0-1-same-origin-policy-ignores-a-different-port-number/m-p/27659#M10900</link>
      <description>&lt;P class=""&gt;I tested it both on Django server and FastAPI/Uvicorn. I will be using FastAPI/Uvicorn in this example as it is the simplest one (notice no CORS headers):&lt;/P&gt;&lt;PRE&gt;# main.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}&lt;/PRE&gt;&lt;HR /&gt;&lt;PRE&gt;$ uvicorn main:app --reload  
INFO: Uvicorn running on http://127.0.0.1:8000  &lt;/PRE&gt;&lt;HR /&gt;&lt;P class=""&gt;For the frontend I will be using Visual Studio Code Live Server from which I will make a request. It’s a simple html page that contains a button and this JavaScript script:&lt;/P&gt;&lt;PRE&gt;const button2 = document.getElementById("button2");
button2.addEventListener("click", () =&amp;gt; {
  fetch("http://127.0.0.1:8000/")
    .then((response) =&amp;gt; {
      return response.json();
    })
    .then((data) =&amp;gt; console.log(data));
});&lt;/PRE&gt;&lt;P class=""&gt;Since both of them are running, let’s click on a button and make a request from &lt;A href="http://127.0.0.1:5500/" target="_blank" rel="noopener"&gt;http://127.0.0.1:5500/&lt;/A&gt; to &lt;A href="http://127.0.0.1:8000/" target="_blank" rel="noopener"&gt;http://127.0.0.1:8000/&lt;/A&gt; according to Same Origin Policy (a different port number) I should not be able to read the response, yet I can.&lt;/P&gt;&lt;P class=""&gt;Now let’s change &lt;A href="http://127.0.0.1:5500/" target="_blank" rel="noopener"&gt;http://127.0.0.1:5500/&lt;/A&gt; to &lt;A href="http://localhost:5500/" target="_blank" rel="noopener"&gt;http://localhost:5500/&lt;/A&gt; and make the reuqest again, this time it does care about SOP&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at &lt;A href="http://127.0.0.1:8000/" target="_blank" rel="noopener"&gt;http://127.0.0.1:8000/&lt;/A&gt;. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P class=""&gt;I tested it on Chromium the response is blocked in both cases, so why is Firefox bahaving like this?&lt;/P&gt;&lt;HR /&gt;&lt;P class=""&gt;Some more info about the request and response from web developer tools network tab:&lt;/P&gt;&lt;P class=""&gt;from &lt;A href="http://127.0.0.1:5500/" target="_blank" rel="noopener"&gt;http://127.0.0.1:5500/&lt;/A&gt; (not blocked):&lt;/P&gt;&lt;PRE&gt;Status
200
OK
Version HTTP/1.1
Transferred 150 B (25 B size)
Referrer Policy strict-origin-when-cross-origin
Request Priority Highest  
...
Response
HTTP/1.1 200 OK
date: Thu, 23 Mar 2023 10:07:30 GMT
server: uvicorn
content-length: 25
content-type: application/json
...
Request
GET / HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://127.0.0.1:5500/
Origin: http://127.0.0.1:5500
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site  &lt;/PRE&gt;&lt;P class=""&gt;from &lt;A href="http://localhost:5500/" target="_blank" rel="noopener"&gt;http://localhost:5500/&lt;/A&gt; (blocked):&lt;/P&gt;&lt;PRE&gt;Status
200
OK
Version HTTP/1.1
Transferred 150 B (25 B size)
Referrer Policy strict-origin-when-cross-origin
Request Priority Highest  
...
Response  
HTTP/1.1 200 OK
date: Thu, 23 Mar 2023 10:09:30 GMT
server: uvicorn
content-length: 25
content-type: application/json  
...
Request
GET / HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:5500/
Origin: http://localhost:5500
Connection: keep-alive
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site  &lt;/PRE&gt;&lt;P class=""&gt;I also noticed that even thought it doesn’t console.log the response from blocked &lt;A href="http://localhost:5500/" target="_blank" rel="noopener"&gt;http://localhost:5500/&lt;/A&gt;, response tab has visible JSON payload &lt;FONT color="#3366FF"&gt;&lt;EM&gt;message &lt;FONT color="#FF00FF"&gt;"Hello World"&lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt; with this info above &lt;FONT color="#3366FF"&gt;&lt;EM&gt;Response body is not available to scripts (Reason: CORS Missing Allow Origin)&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 10:57:56 GMT</pubDate>
      <guid>https://connect.mozilla.org/t5/discussions/111-0-1-same-origin-policy-ignores-a-different-port-number/m-p/27659#M10900</guid>
      <dc:creator>zebra-f</dc:creator>
      <dc:date>2023-03-23T10:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: [111.0.1] Same Origin Policy ignores a different port number.</title>
      <link>https://connect.mozilla.org/t5/discussions/111-0-1-same-origin-policy-ignores-a-different-port-number/m-p/49678#M17759</link>
      <description>&lt;P&gt;Do you have HTTPS-only mode enabled? If so, this sounds like &lt;A href="https://bugzilla.mozilla.org/show_bug.cgi?id=1751105" target="_blank"&gt;https://bugzilla.mozilla.org/show_bug.cgi?id=1751105&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 20:09:00 GMT</pubDate>
      <guid>https://connect.mozilla.org/t5/discussions/111-0-1-same-origin-policy-ignores-a-different-port-number/m-p/49678#M17759</guid>
      <dc:creator>tanriol</dc:creator>
      <dc:date>2024-01-18T20:09:00Z</dc:date>
    </item>
  </channel>
</rss>

