Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

LFI and RCE protection guidelines #2580

Merged
merged 5 commits into from
Jul 25, 2018
Merged

Conversation

kalpmehta
Copy link
Contributor

@kalpmehta kalpmehta commented Jul 22, 2018

LFI and RCE protection guidelines. Also formatted Security Guidelines.

This PR is a:

  • New topic
  • Content update
  • Content fix or rewrite
  • Bug fix or improvement

Summary

Includes LFI and RCE protection guidelines.

whatsnew
Added local file inclusion (LFI) and remote code execution (RCE) protection guidelines to the Code Magento Standards.

LFI and RCE protection guidelines
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jul 22, 2018

CLA assistant check
All committers have signed the CLA.

@jeff-matthews jeff-matthews requested a review from buskamuza July 23, 2018 12:54
@jeff-matthews
Copy link
Contributor

@buskamuza, please review the LFI and RCE guidelines that @kalpmehta added.

@jeff-matthews jeff-matthews self-assigned this Jul 23, 2018
@@ -707,7 +707,7 @@ class SampleEventObserverThatModifiesInputs

15.1. Use prepared statements for SQL queries.

15.2. Broken Authentication protection.
###15.2. Broken Authentication protection.
Copy link
Contributor

Choose a reason for hiding this comment

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

@kalpmehta, you need to remove all of the hashtags that you added. They're rendering as plaintext in the HTML.

@kalpmehta
Copy link
Contributor Author

@jeff-matthews that's weird, removed all the hashtags as requested.

@@ -761,6 +761,18 @@ class SampleEventObserverThatModifiesInputs

15.8. Frequently update the third-party libraries used in the project/component to eliminate known vulnerabilities.

15.9. LFI protection.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include abbreviation explanation, as in "13. Command line interface (CLI)".


15.10. RCE protection.

15.10.1. SHOULD avoid usage of eval(), passthru(), system(), shell_exec()
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

@szurek szurek Jul 23, 2018

Choose a reason for hiding this comment

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

We should rephrase 15.10.1 for clarity.

SHOULD NOT use eval(), passthru(), system, shell_exec().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @buskamuza for that.
@szurek sure, totally makes sense.

@buskamuza
Copy link
Contributor

buskamuza commented Jul 23, 2018

@szurek, @melnikovi , @paliarush , @akaplya , @DrewML , please review.

15.10.1. SHOULD avoid usage of eval(), passthru(), system(), shell_exec()

15.10.2. SHOULD NOT directly pass user-submitted values to include*(), require*(), create_function(), fopen(), preg_replace()

<!-- LINKS: DEFINITIONS AND ADDRESSES -->
Copy link
Member

Choose a reason for hiding this comment

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

Can we add that we recommend using readonly filesystem? Ability to modify files can lead to many different attacks. Maybe in a new section, since it's more general?

Copy link
Contributor

Choose a reason for hiding this comment

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

Readonly filesystem is not something implemented on the application level, so there is nothing (except validation) developers can do to follow the requirement.

15.10.1. SHOULD avoid usage of eval(), passthru(), system(), shell_exec()

15.10.2. SHOULD NOT directly pass user-submitted values to include*(), require*(), create_function(), fopen(), preg_replace()

Copy link

Choose a reason for hiding this comment

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

I'd recommend adding:

15.10.3. SHOULD NOT use user-submitted data for variable functions.

Maybe a better way to phrase this? I'm referring to $userParam($userData);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@szurek nice addition. Just added.

15.10.1. SHOULD NOT use eval(), passthru(), system(), shell_exec(), serialize(), unserialize(), md5(), srand(), mt_srand()

15.10.2. SHOULD NOT directly pass user-submitted values to include*(), require*(), create_function(), fopen(), preg_replace()

<!-- LINKS: DEFINITIONS AND ADDRESSES -->
Copy link
Member

Choose a reason for hiding this comment

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

@kalpmehta what do you think about adding that we recommend using readonly filesystem? Ability to modify files can lead to many different attacks. Maybe in a new section, since it's more general?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree it's best as per security to only allow read-only file access. I was wondering what if some extension or custom development needs file write operations as well. There should not be any issues as long as user-submitted values are not passed to these functions.

Copy link
Member

Choose a reason for hiding this comment

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

If extension needs to write/modify files, these files should be located in directories application not trying to include/execute files from (pub/media, var). It's very tricky as sometimes attacks because possible as combination of multiple vulnerabilities.


15.10. Remote Code Execution (RCE) protection.

15.10.1. SHOULD NOT use eval(), passthru(), system(), shell_exec(), serialize(), unserialize(), md5(), srand(), mt_srand()
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have most of the functions from 15.10.1 prohibited by our static tests. @melnikovi, in scope of CR automation initiative, could you please double check if any of these are not covered yet.

@kalpmehta If we make sure that all these functions are covered by static tests, does it make sense to have this section?

Copy link
Member

Choose a reason for hiding this comment

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

@paliarush yes, will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paliarush I think it makes sense to list all the unsecure functions so that any engineer who comes to refer these guidelines becomes aware of not using those functions at all. This would also be useful to engineers/architects who does manual code reviews or writes code without running tests. However, I am open to remove that section if you think so!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the section itself makes sense. Though in the future we'd like to cover as many as possible with automated tests.

@buskamuza
Copy link
Contributor

✅ review passed from architecture side. Great addition to the guidelines!

@jeff-matthews jeff-matthews added Major Update Significant original updates to existing content 2.2.x 2.3.x Magento 2.3 related changes labels Jul 25, 2018
@jeff-matthews jeff-matthews added the Technical Updates to the code or processes that alter the technical content of the doc label Jul 25, 2018
@jeff-matthews jeff-matthews merged commit 20ce863 into magento:master Jul 25, 2018
@kalpmehta kalpmehta deleted the patch-3 branch July 25, 2018 17:23
@dshevtsov
Copy link
Collaborator

@jeff-matthews please add whatsnew

magento-devops-reposync-svc pushed a commit that referenced this pull request Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2.2.x 2.3.x Magento 2.3 related changes Major Update Significant original updates to existing content Technical Updates to the code or processes that alter the technical content of the doc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants