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

feat: improve HTTP redirects behavior #262

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

pyrooka
Copy link
Member

@pyrooka pyrooka commented Nov 27, 2023

This commit modifies the Node core so that it will include "safe" headers when performing a cross-site redirect where both the original and redirected hosts are within IBM's "cloud.ibm.com" domain.

Checklist
  • npm test passes (tip: npm run lint-fix can correct most style issues)
  • tests are included
  • documentation is changed or added

This commit modifies the Node core so that it will include "safe" headers
when performing a cross-site redirect where both the original and redirected
hosts are within IBM's "cloud.ibm.com" domain.

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

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

Looks good.
Only suggestion is to add a couple tests

@@ -9,6 +9,6 @@ Bug fixes and new features should include tests whenever possible.
##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [ ] `npm test` passes (tip: `npm run lint-fix` can correct most style issues)
- [ ] `npm test` passes (tip: `npm run lint:fix` can correct most style issues)
Copy link
Member

Choose a reason for hiding this comment

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

good catch!


// Returns true iff safe headers should be copied to a redirected request.
function shouldCopySafeHeadersOnRedirect(fromHost: string, toHost: string): boolean {
return fromHost.endsWith('.cloud.ibm.com') && toHost.endsWith('.cloud.ibm.com');
Copy link
Member

Choose a reason for hiding this comment

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

This logic should work as long as we are also supporting the scenario where a redirection to the same host also results in the safe headers being copied, which I assume is the case since you're not completely overriding axios' redirection behavior (presumably) :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Those scenarios are covered by the unit tests now and yes, we are not overriding the whole redirection behavior, it's just a sort of post-processing in the chain, before sending the next, redirected request.

});

it('should include safe headers within cloud.ibm.com domain', async () => {
const url1 = 'http://region1.cloud.ibm.com';
Copy link
Member

Choose a reason for hiding this comment

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

let's use https in these URLs :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed! I also change the protocols in my Python core PR, because I used HTTP there too.

@@ -0,0 +1,211 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

need to add tests for redirects to the same host:

  • both are region1.cloud.ibm.com
  • both are region2.notcloud.ibm.com

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>

chore: small improvements

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>

chore: fix tests

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>

chore: fix unit tests

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>

chore: lint fix

Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants