Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit adding the osd-version header when the Fetch request is to an external origin #3643

Conversation

AMoo-Miki
Copy link
Collaborator

@AMoo-Miki AMoo-Miki commented Mar 21, 2023

Description

  • Making fetch requests using core/public/http/fetch, an osd-version header is forcefully added, even to external requests. This change examines the destination and only adds the header to relative URLs and those that are to OSD itself.
  • This change also adds osd-xsrf to calls that use osd-version incorrectly to satisfy XSRF protection

Issues Resolved

Fixes #3277

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@AMoo-Miki AMoo-Miki requested a review from a team as a code owner March 21, 2023 18:26
Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

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

I think the failures since we utilized this for XRSF.

if (!isSafeMethod(request.route.method) && !hasVersionHeader && !hasXsrfHeader) {
tries to find a header and then it can't find it so it throws the error.

It might not be the proper way of handling XSRF but by removing it causes these errors to be thrown.

@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from 4236cef to fb9468f Compare March 22, 2023 18:55
@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from fb9468f to c55ee28 Compare March 22, 2023 19:34
@AMoo-Miki
Copy link
Collaborator Author

if (!isSafeMethod(request.route.method) && !hasVersionHeader && !hasXsrfHeader) {

If it is a GET or OPTIONS call, in will not fail and also if it contains the osd-xsrf. 621bf0e suggests osd-version used to be used for XSRF prior to K5 and they never cared to clean the code up over the next 6 years. I have added osd-xsrf to any call that was using osd-version for XSRF protection.

@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from c55ee28 to d8be993 Compare March 22, 2023 19:39
@AMoo-Miki AMoo-Miki changed the title Omit adding the osd-version header when the Fetch request was explicitly asked to not prepend the basePath Omit adding the osd-version header when the _Fetch_ request is to an external origin Mar 22, 2023
@AMoo-Miki AMoo-Miki changed the title Omit adding the osd-version header when the _Fetch_ request is to an external origin Omit adding the osd-version header when the Fetch request is to an external origin Mar 22, 2023
@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from d8be993 to f0b5ae9 Compare March 22, 2023 19:46
@AMoo-Miki AMoo-Miki requested a review from kavilla March 22, 2023 19:47
@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from f0b5ae9 to 18a3b21 Compare March 22, 2023 19:51
@joshuarrrr
Copy link
Member

@AMoo-Miki There are some snapshots that need updating.

@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from 18a3b21 to ead7e34 Compare March 23, 2023 16:01
@AMoo-Miki
Copy link
Collaborator Author

@AMoo-Miki There are some snapshots that need updating.

Oops; i thought i committed and pushed it... just did.

…external origin

* Making `fetch` requests using core/public/http/fetch, an `osd-version` header is forcefully added, even to external requests. This change examines the destination and only adds the header to relative URLs and those that are to OSD itself.
* This change also adds `osd-xsrf` to calls that use `osd-version` incorrectly to satisfy XSRF protection

Fixes opensearch-project#3277

Signed-off-by: Miki <miki@amazon.com>
@AMoo-Miki AMoo-Miki force-pushed the limit-osd-version-header-in-fetch branch from c71b2ac to ff6f6f6 Compare April 5, 2023 15:59
Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

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

I think looks good to me. Pulled it down working. It's also working with the basic settings for security plugin.

One thing I'm not able to completely test is if any functionality relied on the osd-version header being present just so the redirect can be attached to the request and not fail.

For example, on main:
This succeeds:

curl localhost:5601/hdn/api/status -ku 'admin:admin'

This succeeds:

curl localhost:5601/hdn/api/status -ku 'admin:admin' -H osd-version:3.0.0

This succeeds:

curl localhost:5601/hdn/api/status -ku 'admin:admin' -H osd-version:

This fails:

curl localhost:5601/hdn/api/status -ku 'admin:admin' -H osd-version:3.5.0

Which makes sense because the version mismatch. So if any functionality outside of what I tested relied on the osd-version and utilized the fetch call might be broken if the fetch was passed from one request to another.

So I don't know want to block it on something that I can't test especially if the value being not present still works for us. But I do believe we might want to mention in higher in the changelog.

Like something that mentions,

HTTP Fetch from Core OpenSearch Dashboards no longer default appends the osd-version.

@AMoo-Miki
Copy link
Collaborator Author

Rocky, this change makes sure osd-xsrf is used all over and only removed node-version when the call is to a destination outside of OSD; any call to OSD will have node-version.

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

@AMoo-Miki Is there a follow-up issue already created to keep track of these todos?

@@ -54,8 +54,9 @@ export const createXsrfPostAuthHandler = (config: HttpConfig): OnPostAuthHandler
const hasVersionHeader = VERSION_HEADER in request.headers;
const hasXsrfHeader = XSRF_HEADER in request.headers;

// ToDo: Remove !hasVersionHeader; `osd-version` incorrectly used for satisfying XSRF protection
Copy link
Member

Choose a reason for hiding this comment

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

nit - todo comments should have issues opened to link to.

@joshuarrrr joshuarrrr merged commit 0762566 into opensearch-project:main Apr 17, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 17, 2023
…external origin (#3643)

* Making `fetch` requests using core/public/http/fetch, an `osd-version` header is forcefully added, even to external requests. This change examines the destination and only adds the header to relative URLs and those that are to OSD itself.
* This change also adds `osd-xsrf` to calls that use `osd-version` incorrectly to satisfy XSRF protection

Fixes #3277

Signed-off-by: Miki <miki@amazon.com>
(cherry picked from commit 0762566)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
ashwin-pc pushed a commit that referenced this pull request Apr 18, 2023
…quest is to an external origin (#3867)

* Omit adding the `osd-version` header when the Fetch request is to an external origin (#3643)

* Making `fetch` requests using core/public/http/fetch, an `osd-version` header is forcefully added, even to external requests. This change examines the destination and only adds the header to relative URLs and those that are to OSD itself.
* This change also adds `osd-xsrf` to calls that use `osd-version` incorrectly to satisfy XSRF protection

Fixes #3277

Signed-off-by: Miki <miki@amazon.com>
(cherry picked from commit 0762566)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

* add changelog

Signed-off-by: Josh Romero <rmerqg@amazon.com>

---------

Signed-off-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
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.

[BUG] Fetch calls pass custom headers for every 302 request causing CORS
4 participants