Closed Bug 1569715 Opened 5 years ago Closed 4 years ago

CORS preflight requests are cached when 'Disable cache' is checked.

Categories

(DevTools :: Netmonitor, defect, P2)

68 Branch
defect

Tracking

(firefox79 fixed, firefox84 verified, firefox85 verified)

VERIFIED FIXED
Firefox 79
Tracking Status
firefox79 --- fixed
firefox84 --- verified
firefox85 --- verified

People

(Reporter: me, Assigned: valentin)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [necko-triaged])

Attachments

(3 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

Steps to reproduce:

Close and reopen Firefox.
Open the network developer tools and check 'Disable cache'
Trigger a CORS request that will be preflighted and usually cached (Access-Control-Max-Age set in the response) twice.

Actual results:

The first request shows a preceding OPTIONS preflight in the network tools, the second does not.

Expected results:

Both requests should have triggered preflights as caching was disabled.

Hi,
i'm not able to reproduce the reported behavior. Would you please attach a minimal test case to trigger the request you've mentioned? In the meantime i will assign a component to make one of our devs have a look. Feel free to change it if you consider it wrong

Regards
David

Flags: needinfo?(me)
Component: Untriaged → Netmonitor
Product: Firefox → DevTools

@David, we need a reproducible test case to make progress on this bug. Can you please provide one?
Otherwise we'll close the report as invalid (non reproducible) :-(

Honza

Sorry, totally missed the first replies. The behavior I observed is still happening (on a different computer) if I follow the above instructions using this page (e.g. edit the first pi := 3.14159 text box to trigger a request). I'm pretty busy now and no longer have access to that backend's source code to be able to quickly strip it down, but if there's a specific format of test case you want I can try to make one.

Flags: needinfo?(me)

(In reply to David Boles from comment #3)

Sorry, totally missed the first replies. The behavior I observed is still happening (on a different computer) if I follow the above instructions using this page (e.g. edit the first pi := 3.14159 text box to trigger a request). I'm pretty busy now and no longer have access to that backend's source code to be able to quickly strip it down,

I am still unsure how to see the issue.

The first request shows a preceding OPTIONS preflight in the network tools, the second does not.

I am not seeing a request with OPTIONS method in the Net panel.

but if there's a specific format of test case you want I can try to make one.

There is no specific format. We just need a simple page (online or attached to this bug) that can be used to see the problem. You can use PHP or NodeJS, if that helps.

Honza

Flags: needinfo?(me)

I could finally repro this issue.

STR:

  1. Load https://www.openpolicyagent.org/docs/latest/policy-language/
  2. Open DevTools and select the Network panel
  3. Check Disable Cache
  4. Modify the first input box in The Basics section (default value is: pi := 3.14159)
  5. Observe two requests in the Network panel
    • OPTIONS preflight
    • POST
  6. Edit again, observe just one request
    • POST
      The preflight request is missing, seems like it's cached, which is wrong since the cache is disabled -> BUG

Honza

Has STR: --- → yes
Priority: -- → P3
Status: UNCONFIRMED → NEW
Ever confirmed: true

(Clearing ni? as we have an STR)

P2, as this makes it harder to debug and fix CORS rules efficiently.

Flags: needinfo?(me)
Priority: P3 → P2

Nhi, given how important CORS is for a secure web, not having a proper Disable Cache support in DevTools is biting developers. Who do you think could help on the Necko side to unblock this and at least give some guidance on scope this fix entails?

Flags: needinfo?(nhnguyen)
See Also: → 1528603

Michal, could you outline the steps needed to fix this? Thanks!

Flags: needinfo?(nhnguyen) → needinfo?(michal.novotny)

(In reply to Jan Honza Odvarko [:Honza] (always need-info? me) from comment #5)

I could finally repro this issue.

STR:

  1. Load https://www.openpolicyagent.org/docs/latest/policy-language/
  2. Open DevTools and select the Network panel
  3. Check Disable Cache

What exactly this check box should mean? Should Firefox behave like HTTP cache was disabled (the hover text of the checkbox says so)? Preflight responses are not cached in HTTP cache, so if HTTP cache is disabled preflight responses are still returned from sPreflightCache (https://searchfox.org/mozilla-central/rev/7fd1c1c34923ece7ad8c822bee062dd0491d64dc/netwerk/protocol/http/nsCORSListenerProxy.cpp#181). If you really want to skip the cache, we should check the load flags of aRequestChannel in nsCORSListenerProxy::StartCORSPreflight() and don't lookup the entry if nsIRequest::LOAD_BYPASS_CACHE was specified.

Flags: needinfo?(michal.novotny) → needinfo?(odvarko)

What exactly this check box should mean?

It should disable any network-related caching in Firefox for this tab (DNS, CORS preflight). This is especially important for developers as cached HTTP, CORS, DNS, etc. information is can be subject to iterative changes in a development environment and caching gets in the way.

Just clearing NI since Harald already replied.

Flags: needinfo?(odvarko)

Michal, could you take a look?
Thanks.

Severity: normal → S3
Flags: needinfo?(michal.novotny)
Flags: needinfo?(michal.novotny)
Whiteboard: [necko-triaged]

Honza, could you clarify if we have all we need for the Devtools side, or would this depend on the Necko team to implement/fix?

Flags: needinfo?(odvarko)
Blocks: 1484005
Flags: needinfo?(odvarko)

Summary:

  1. Valid test case is in comment #5 and I can easily use it to reproduce this issue

  2. The Disable Cache checkbox should disabled any network-related caching in Firefox for this tab (DNS, CORS preflight) as stated in comment #10

  3. This needs to be fixed on the platform as stated in comment #9

Preflight responses are not cached in HTTP cache, so if HTTP cache is disabled preflight responses are still returned from sPreflightCache (https://searchfox.org/mozilla-central/rev/7fd1c1c34923ece7ad8c822bee062dd0491d64dc/netwerk/protocol/http/nsCORSListenerProxy.cpp#181). If you really want to skip the cache, we should check the load flags of aRequestChannel in nsCORSListenerProxy::StartCORSPreflight() and don't lookup the entry if nsIRequest::LOAD_BYPASS_CACHE was specified.

  1. There is also bug 1376253 (with a test case available) that reports missing preflight request. Worth to include it in the investigation (to see whether it's related).

  2. There is also bug 1528603 (reported in Networking) component that is very related. It's about viewing and clearing CORS cache. It also contains a few more links to the platform code base.

Nhi, supporting Firefox security features (including CORS) is increasingly important. Could someone please look into this bug?

Thanks,
Jan

Flags: needinfo?(nhnguyen)
Assignee: nobody → michal.novotny
Flags: needinfo?(nhnguyen)
Pushed by mnovotny@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/29d1be2b96f9 Don't lookup CORS preflight cache when request bypasses HTTP cache, r=mayhemer,necko-reviewers,valentin
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 79
No longer blocks: 1642034
See Also: → 1669780
Regressions: 1669780

It seems we need another way to bypass preflight cache for devtools.
If I read the code correctly, it seems we simple change the pref devtools.cache.disabled when Disable Cache is toggled. Maybe we can simply check if devtools.cache.disabled is true instead checking load flags at here.

Honza, what do you think?

Status: RESOLVED → REOPENED
Flags: needinfo?(odvarko)
Resolution: FIXED → ---
Assignee: michal.novotny → valentin.gosu

Clear ni to Honza, since he is the reviewer.

Flags: needinfo?(odvarko)
Pushed by valentin.gosu@gmail.com: https://hg.mozilla.org/integration/autoland/rev/1754415059f5 Don't lookup CORS preflight cache when devtools 'Disable cache' is checked r=necko-reviewers,kershaw
Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED
QA Whiteboard: [qa-84b-p2]

I managed to reproduce the issue using an older version of Nightly on Windows 10 x64. I retested everything on macOS 10.13, Ubuntu 18.04 and Windows 10 x64 using Firefox 84.0 and Nightly 85.0a1. The issue is not reproducing anymore.

Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: