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

Added check for HTTP_ORIGIN index (fix #1) #2

Merged
merged 3 commits into from
Jul 25, 2022
Merged

Added check for HTTP_ORIGIN index (fix #1) #2

merged 3 commits into from
Jul 25, 2022

Conversation

bluesn4rfer
Copy link
Contributor

Description

Added an if statement to the top of function isOriginAllowed to check if the HTTP_ORIGIN index was set in $_SERVER and return false if it is not found

This change prevents a notice exception from being thrown when $_SERVER['HTTP_ORIGIN'] does not exist and allows a user to view the resource

This is not a breaking change because if $_SERVER['HTTP_ORIGIN'] is set, it would continue the rest of the flow inside function isOriginAllowed

Related Issue

#1 ErrorException thrown with message "Undefined index: HTTP_ORIGIN"
After creating a default leaf mvc project, then attempting to view the project the user receives a notice exception.

Copy link
Member

@mychidarko mychidarko left a comment

Choose a reason for hiding this comment

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

This will throw CORS errors even when the origin is correct, but HTTP_ORIGIN is not set. The best thing to do here will be to check if HTTP_ORIGIN is set, and find another way to set the $origin variable.

Something like

$origin = $_SERVER['HTTP_ORIGIN'] ?? 'GET ORIGIN HERE'; // L 129

@mychidarko mychidarko added bug Something isn't working fix Patch for some broken feature and removed bug Something isn't working labels Jul 25, 2022
Copy link
Member

@mychidarko mychidarko left a comment

Choose a reason for hiding this comment

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

The http_referrer is apparently unsafe and remote_addr may return the IP instead. The best means may be to check for http_origin and manually check for the Origin header.

Sorry for all this 😂

@bluesn4rfer
Copy link
Contributor Author

Hi,

Looking in Google Chrome developer tools, there does not appear to be an Origin header sent.

This is an old answer from stack overflow https://stackoverflow.com/questions/15512331/chrome-adding-origin-header-to-same-origin-request

I'm still researching this some, but it looks like same-origin requests might not be required to send Origin header & might be why HTTP_ORIGIN is not populated. If HTTP_ORIGIN is always populated when cross-origin requests occur than the original commit of returning false & skipping the Allow-Origin header in the response maybe fine?

NoOrigin

@mychidarko
Copy link
Member

mychidarko commented Jul 25, 2022

Oh yeah. That's true, but in cases like yours, you'll get errors if you simply return false.

@bluesn4rfer
Copy link
Contributor Author

Perhaps using $_SERVER['HTTP_HOST'] when $_SERVER['HTTP_ORIGIN'] is not found?

@mychidarko
Copy link
Member

Yes, thanks

@mychidarko
Copy link
Member

Thanks for the PR

@mychidarko mychidarko merged commit 10934a7 into leafsphp:main Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Patch for some broken feature
Projects
Status: Published
Development

Successfully merging this pull request may close these issues.

2 participants