Skip to content

Conversation

@Jesse-Cameron
Copy link
Contributor

@Jesse-Cameron Jesse-Cameron commented Jun 2, 2024

Summary:

Experimental debugger support for custom hostnames.

Currently the experimental debugger rejects all requests that don't come from the localhost hostname. We are using the --host flag when starting the react native. It would be good if the debugger supported this.

see: #2396

Test Plan:

I have manually tested this PR in a clean project using:

npm react-native start --experimental-debugger --host 0.0.0.0

(after linking packages locally)

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@szymonrybczak
Copy link
Collaborator

Amazing, makes sense! Thanks for contribution! Is there anything blocking you from making this PR ready for review?

@Jesse-Cameron Jesse-Cameron marked this pull request as ready for review June 5, 2024 07:01
@Jesse-Cameron
Copy link
Contributor Author

Hey @szymonrybczak,

I just wanted to do a quick test in a clean repo. Seems to work well so happy for this to be reviewed now!

Comment on lines 20 to 48
it('it should block requests from different origins', () => {
req.headers.origin = 'https://example.com';
const middleware = securityHeadersMiddleware({});
middleware(req, res, next);
expect(next).toHaveBeenCalledWith(expect.any(Error));
});

it('it should allow requests from localhost', () => {
req.headers.origin = 'http://localhost:3000';
const middleware = securityHeadersMiddleware({});
middleware(req, res, next);
expect(next).toHaveBeenCalled();
});

it('it should allow requests from devtools', () => {
req.headers.origin = 'devtools://devtools';
const middleware = securityHeadersMiddleware({});
middleware(req, res, next);
expect(next).toHaveBeenCalled();
});

it('it should allow requests from custom host if provided in options', () => {
req.headers.origin = 'http://customhost.com';
const middleware = securityHeadersMiddleware({host: 'customhost.com'});
middleware(req, res, next);
expect(next).toHaveBeenCalled();
});

it('it should block requests from custom host if provided in options but not matching', () => {
Copy link
Member

Choose a reason for hiding this comment

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

very minor nit: all test titles start with "it" which is kinda redundant 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good shout. Will fix that up!

@Jesse-Cameron
Copy link
Contributor Author

Thanks for the reviews folks! Have cleaned up the test titles and rebased upstream/main :)

@thymikee thymikee merged commit 9c813dc into react-native-community:main Jun 5, 2024
@thymikee
Copy link
Member

thymikee commented Jun 5, 2024

Thank you for the contribution @Jesse-Cameron! 🙌🏼

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