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

Proposal: HTTP Response - Fix crash on CSP methods CSP is disabled #2506

Merged
merged 1 commit into from
Jan 23, 2020

Conversation

najdanovicivan
Copy link
Contributor

Description
If CSP is disabled property $CSP in HTTP/Response is not initialized.

If we try to access the CSP methods on the request object anywhere in code with CSP disabled it will crash the framework with "Call to a member function …. on null "

In order to avoid this CSP object can be initiated regardless of CSP config.

I’m aware that this is not the most efficient way to bypass the issue but some mechanism for disabling CSP should exist without having to do modifications everywhere in code.

Maybe better idea will be to create mock class to be loaded instead which will respond with catchall magic methods like __call __set __get ….. But I don’t know if it is worth doing it as it will require adding additional class in framework.

Fixes #2456

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

…abled

If CSP is disabled property $CSP in HTTP/Response is not initialized.

If we try to access the CSP methods on the request object anywhere in code with CSP disabled it will crash the framework with "Call to a member function …. on null "

In order to avoid this CSP object can be initiated regardless of CSP config.

I’m aware that this is not the most efficient way to bypass the issue but some mechanism for disabling CSP should exist without having to do modifications everywhere in code.

Maybe better idea will be to create mock class to be loaded instead which will respond with catchall  magic methods like __call __set __get ….. But I don’t know if it is worth doing it as it will require adding additional class in framework.

Ref codeigniter4#2456

Added unit test testCSPDisabled()
@najdanovicivan
Copy link
Contributor Author

I've additionally added Unit Test to cover such case.

@lonnieezell
Copy link
Member

I think this is a fine solution. Using a mock class would still have the performance cost of locating and loading the file so we wouldn't gain anything there.

Thanks!

@lonnieezell lonnieezell merged commit 0eedc0e into codeigniter4:develop Jan 23, 2020
@najdanovicivan najdanovicivan deleted the csp-fix branch January 27, 2020 14:05
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.

Bug: if not CSPEnaled but i have some
2 participants