cakephpsecurityassessment mozilla .cakephpsecurityassessment mozilla october17,2017–version1.0

Download CakePHPSecurityAssessment Mozilla .CakePHPSecurityAssessment Mozilla October17,2017–Version1.0

Post on 27-Sep-2018

217 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • CakePHP Security AssessmentMozillaOctober 17, 2017 Version 1.0

    Prepared forGervase Markham, MozillaLarry E. Masters and Mark Story, CakePHP

    Prepared byBrandon BerniePaul TetreauRyan Koppenhaver

    2017 NCC Group

    Prepared by NCC Group Security Services, Inc. for Mozilla. Portions of this document and the templatesused in its production are the property of NCC Group and cannot be copied (in full or in part) withoutNCC Groups permission.

    While precautions have been taken in the preparation of this document, NCC Group the publisher, andthe author(s) assume no responsibility for errors, omissions, or for damages resulting from the use of theinformation contained herein. Use of NCCGroups services does not guarantee the security of a system,or that computer intrusions will not occur.

  • Executive SummarySynopsisIn the Summer of 2017, Mozilla engaged NCC Groupto perform a security assessment of the CakePHPframework under the Secure Open Source track of theMozilla Open Source Support program, which aims tohelp improve the security of Free and Open SourceSoftware by funding security audits of vital projects.

    CakePHP is a web application framework that providesaModel-View-Controller (MVC) architecture. It is writtenin PHP and licensed under the MIT license. Its homepage is https://cakephp.org/, and the current version atthe time of the test was 3.5.0-RC1.

    NCC Group identified specific security flaws that couldaffect certain applications that use specific CakePHPfeatures, as well as areas in whichCakePHPs defaults areinsecure.

    The assessment was done by three consultants overthree calendar weeks, from July 31 to August 18, 2017.The consultants reviewed theCakePHP source code andperformeddynamic testing using the standardCakePHPtutorial application aswell as other test applications builtby the consultants.

    ScopeNCC Groups evaluation included:

    The CakePHP framework: The web application frame-work provides behind the scenes elements suchas the HTTP Server, Middleware, Router, MVC baseclasses; as well as developer APIs including Object-Relational Mapper (ORM) functionality and HTMLhelpers.

    cake: The CakePHP console provides command-linefunctionality such as a development server, routeinformation, and an interactive REPL, as well as aframework to build custom scripts to interact with aCakePHP application.

    bake: The bake console application performs codegeneration based on a database schema or variouscommand line arguments.

    Additionally, the Bookmarker tutorial application1 wasused as a reference application, in conjunction with testapplications generated using bake.

    The assessment targeted the 3.5.0-RC1 release ofCakePHP, version 1.3.7 of bake, and commit faf9e003of bookmarker-tutorial.

    Key FindingsThe assessment did not uncover any large-scale, di-rectly exploitable flaws in CakePHP that would affectall applications using the framework, but did exposevarious issues which could impact applications whichuse particular elements of CakePHP functionality.

    In addition, NCC Group noted some areas in whichwriting a secure application would require developersto explicitly override defaults provided by the frame-work; these were reported as findings where they didnot appear to be clearly documented, or where NCCGroup believes them to be sufficiently dangerous as towarrant a direct call-out.

    Some of the most notable issues found were:

    CakePHP provides insecure defaults for attributeaccessibility in mass assignment. This could allowmalicious users to modify data in an application thatthey should not be allowed to, such as changing theprice of items in a shopping cart, or changing theirown user account to be an administrator.

    Applications could be exposed to cross-site scriptingvulnerabilities if untrusted URLs are passed to someof CakePHPs HTML helper methods, or if untrustedvalues are used in attribute keys.

    Applications using CakePHPs XML utility class couldbe exposed to a denial of service via an entityexpansion attack which consumes a large amount ofserver memory relative to the request size.

    Strategic Recommendations Support templates using a language which performsautomatic HTML escaping, and make it the default.Manually escaping HTML metacharacters in tem-plates is error-prone, and may not work correctly incorner cases such as variables interpolated insideHTML tags or scripts.

    Create consolidated documentation of security bestpractices. This will allow developers to quicklyfamiliarize themselves with areas of concern, andprevent avoidable security mistakes.

    1https://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/intro.html

    2 | CakePHP Security Assessment

    https://cakephp.org/https://github.com/cakephp/cakephp/tree/3.5.0-RC1https://github.com/cakephp/bake/tree/1.3.7https://github.com/cakephp/bookmarker-tutorial/commit/faf9e00369cd8672af8332aa48881c53f162229bhttps://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/intro.html
  • DashboardTarget MetadataName CakePHPType Web Development FrameworkPlatforms PHP 7

    Engagement DataType Web Framework Security

    AssessmentMethod Source ReviewDates 2017-07-31 to 2017-08-18Consultants 3Level ofeffort 45 person-days

    Finding BreakdownCritical Risk issues 0High Risk issues 1Medium Risk issues 5Low Risk issues 9Informational issues 5Total issues 20

    Category BreakdownAccess Controls 4Configuration 1Cryptography 9Data Exposure 1Data Validation 5

    KeyCritical High Medium Low Informational

    3 | CakePHP Security Assessment

  • Table of FindingsFor each finding, NCC Group uses a composite risk score that takes into account the severity of the risk, applicationsexposure and user population, technical difficulty of exploitation, and other factors. For an explanation of NCCGroupsrisk rating and finding categorization, see Appendix A on page 31.

    Title ID RiskMass Assignment Allowed by Default 001 HighUnsafe HTML Templates By Default 003 MediumMultiple Html Helper Methods Do Not Escape URLs 004 MediumHTML Helpers Do Not Escape Attribute Keys 005 MediumIncorrect X-Forwarded-For Header Parsing Allows IP Spoofing 015 MediumXML Entity Expansion Denial of Service 018 MediumrandomBytes Returns Insecure Random Numbers 009 LowComment Incorrectly Advertises Mitigation for User Enumeration Timing Attack 010 LowDigest Authentication Uses Non-Constant-Time Comparisons 012 LowTutorial Application Allows Path Traversal in Pages Controller 014 LowAutoLink Functions Use Predictable and Collision-Prone Hashes 016 LowInconsistent Configuration of Transport Encryption Protocols 019 LowForm Validation Tokens Are Not Associated with Users 020 LowForm Validation Tokens Are Vulnerable to Potential Hash Collisions 021 LowAsset Middleware Can Serve Dot Files 022 LowSetters of Entity Attributes Are Not Always Called 002 InformationalInsecure Default Hashing Algorithm 006 InformationalCertificate Authority Bundle Includes Untrustworthy CAs 007 InformationalInsecure UUID Function 008 InformationalDigest Authentication Uses MD5 Algorithm to Construct Nonces 011 Informational

    4 | CakePHP Security Assessment

  • Finding DetailsFinding Mass Assignment Allowed by Default

    Risk High Impact: High, Exploitability: Medium

    Identifier NCC-CakePHP_2017-001

    Category Access Controls

    Location CakePHP: src/Datasource/EntityTrait.php: 118 Bake: src/Template/Bake/Model/entity.ctp: 25 - 37

    Impact By default, any attribute of an entity may be modified by a request, i.e. a user updating theirpassword would be able to set their privilege level to that of an administrator.

    Description Mass assignment is often used by developers as a convenience mechanism for setting at-tributes of a model, but it can be a problem when a models attributes are overexposed,allowing malicious users to unexpectedly modify sensitive model attributes, such as a usersprivilege level.

    Mass assignment is regulated by the _accessible associative array, which maps entity at-tributes to booleans that indicate whether or not that attribute may be assigned when theentity is updated. The * character is a wildcard that matches any attribute.

    The _accessible array in the EntityTrait trait defaults to allowing all attributes to beassigned:

    protected $_accessible = ['*' => true];

    Similarly, the Bake command defaults to allowing all attributes to be assigned except theprimary key of the model:

    $accessible = [];if (!isset($fields) || $fields !== false) {

    if (!empty($fields)) {foreach ($fields as $field) {

    $accessible[$field] = 'true';}

    } elseif (!empty($primaryKey)) {$accessible['*'] = 'true';foreach ($primaryKey as $field) {

    $accessible[$field] = 'false';}

    }}

    For example, a user model might contain an admin attribute, with a value of True for ad-ministrators and False for other users, a username attribute, and a password attribute. Ifthat entity were vulnerable to mass assignment, a password reset page that permits a user toupdate their password would also permit the user to modify their admin attribute, allowingfor privilege escalation.

    Mass assignment is a very dangerous default, made infamous by Ruby on Rails, whoseGithubrepository was compromised2 by an unauthorized user because of that default. This allowedthe attacker to add their SSH keys to the trusted keys list of the repository.

    Recommendation The accessible attributes list should be empty by default, requiring developers to manually2https://github.com/rails/rails/commit/b83965785db1eec019edf1fc272b1aa393e6dc57

    5 | CakePHP Security Assessment

    https://github.com/cakephp/cakephp/blob/0a5bf84d3bb07108acc5e832315388baa1a4b604/src/Datasource/EntityTrait.php#L118https://github.com/cakephp/bake/blob/53e40910aec77743ed1e30d4925a43b37197729d/src/Template/Bake