Skip to content

Conversation

@JunielKatarn
Copy link
Contributor

@JunielKatarn JunielKatarn commented Mar 12, 2024

Description

Sets HTTP origin URL per filter instance.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Why

A crash can be caused by an inconsistent state when the host app is being shut down and an HTTP request has been scheduled from the JS layer.

This affects the static member OriginPolicyHttpFilter::s_origin.

What

Make the HTTP origin an instance member of OriginPolicyHttpFilter so the value will be bound to the filter's life time.

In most cases, this won't add significant memory overhead because the filter's instance (and its members) is a singleton for the owning resource, module, and React instance.

Testing

Updated tests ValidatePreflightResponseHeadersCaseMismatchSucceeds and ValidatePreflightResponseMainAndContentHeadersSucceeds.

Microsoft Reviewers: Open in CodeFlow

@@ -653,8 +652,7 @@ void WinRTHttpResource::AddResponseHandler(shared_ptr<IResponseHandler> response
client = HttpClient{redirFilter};
} else {
auto globalOrigin = GetRuntimeOptionString("Http.GlobalOrigin");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a public PropertyId, or a setter for ReactPropertyBag/ReactInstanceSettings to allow setting this option on a per instance basis. If someone wanted to have different origins for different RN instances there would still be a synchronization issue here.

We still need the "legacy" GetRuntimeOptionString option for Office's non-abi code paths, but for public use this should all be done using ReactInstanceSettings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can that be addressed in a follow-up PR? (I could use that to re-factor other property ID declarations that are done inefficiently).

This fix is required ASAP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@JunielKatarn JunielKatarn requested a review from acoates-ms March 12, 2024 18:58
@JunielKatarn JunielKatarn merged commit fadb98c into microsoft:main Mar 13, 2024
@JunielKatarn JunielKatarn deleted the OC/8822139/origprop branch March 13, 2024 00:33
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 13, 2024
* Make origin an instance member

* Change files

* Remove s_origin

* Remove redundant namespace
JunielKatarn added a commit to jurocha-ms/react-native-windows that referenced this pull request Mar 13, 2024
* Make origin an instance member

* Change files

* Remove s_origin

* Remove redundant namespace
JunielKatarn added a commit that referenced this pull request Mar 13, 2024
* Make HTTP origin value an instance member (#12821)

* Make origin an instance member

* Change files

* Remove s_origin

* Remove redundant namespace

* Remove change file

* Change files

* Add missing backports

* Use case-insensitive comparison for CORS preflight responses (#11511)

* Remove usage of RestoreUseStaticGraphEvaluation

* Add test ValidatePreflightResponseHeadersCaseMismatchSucceeds

* Use case-insensitive comparer for AllowedHeaders

* Change files

* Revert "Remove usage of RestoreUseStaticGraphEvaluation"

This reverts commit 735b168.

* Rename ConstWcharComparer to CaseInsensitiveComparer

* Update vnext/Desktop.UnitTests/OriginPolicyHttpFilterTest.cpp

Co-authored-by: Danny van Velzen <dannyvv@microsoft.com>

* Remove unused code

* Make ExposedHeaders case-insensitive

---------

Co-authored-by: Danny van Velzen <dannyvv@microsoft.com>

* Remove change file

* clang format

* Remove redundant include

---------

Co-authored-by: Danny van Velzen <dannyvv@microsoft.com>
JunielKatarn added a commit that referenced this pull request Mar 14, 2024
* Make HTTP origin value an instance member (#12821)

* Make origin an instance member

* Change files

* Remove s_origin

* Remove redundant namespace

* Remove change file

* Change files

* Empty commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants