Skip to content

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 <[email protected]>
Signed-off-by: Norbert Biczo <[email protected]>
@pyrooka pyrooka requested review from dpopp07 and padamstx November 27, 2023 14:49
Copy link
Contributor

@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

<!-- 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
Contributor

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
Contributor

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
Contributor

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
Contributor

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 <[email protected]>
Signed-off-by: Norbert Biczo <[email protected]>

chore: small improvements

Signed-off-by: Norbert Biczo <[email protected]>

chore: fix tests

Signed-off-by: Norbert Biczo <[email protected]>

chore: fix unit tests

Signed-off-by: Norbert Biczo <[email protected]>

chore: lint fix

Signed-off-by: Norbert Biczo <[email protected]>
Signed-off-by: Norbert Biczo <[email protected]>
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.

3 participants