SlideShare a Scribd company logo
STATIC ANALYSIS SAVED
MY CODE TONIGHT
PHP UK, LONDON, FEBRUARY 2017.
PHPUK 2017
AGENDA
‣ Under the hood of a static analyzer
‣ What can analyzers do for you
‣ Adopt them now!
‣ Damien Seguy
‣ CTO at exakat
‣ Static code analysis for PHP
‣ Retiring house for oldest 

elephpant
PHPUK 2017
SPEAKER
Elephpant in the death valley
‣ IS IT FAST?
‣ IS THIS BACKWARD COMPATIBLE?
‣ IS THIS SECURE? ‣ IS THIS COMPATIBLE WITH PHP 7?
‣ SHOULD I USE ++$I OR ARRAY_MERGE_RECURSIVE() ?
‣ IS IT TIME FOR LUNCH ?
‣ WHY NOT USE A FRAMEWORK?
PHPUK 2017
STATIC ANALYSIS IS AN EXTRA STEP
EXECUTION
TEXT FILE
OPCODE
CODING CONVENTIONS
PHPUK 2017
STATIC ANALYSIS IS AN EXTRA STEP
EXECUTION
TEXT FILE
OPCODE STATIC ANALYSIS
OPCODE
PHPUK 2017
STATIC ANALYSIS IS AN EXTRA STEP
EXECUTION
TEXT FILE
STATIC ANALYSIS
PHPUK 2017
SWITCH STATEMENTS MAY ONLY CONTAIN ONE DEFAULT CLAUSE
<?php   
switch($x) {   
    case '1' :    
        break;   
    default :    
        break;   
    default :    
        break;   
    case '2' :    
        break;   
}   
PHP Lint
PHPUK 2017
SWITCH STATEMENTS MAY ONLY CONTAIN ONE DEFAULT CLAUSE
switch($x) {   
    case 1 :    
        break;   
    case 0+1 :    
        break;   
    case '1' :    
        break;   
    case true :    
        break;   
    case 1.0 :    
        break;   
    case $y :    
        break;   
}   
PHPUK 2017
STATIC ANALYSIS UNDER THE HOOD
PHP 5 / 7
Calisthenics
ClearPHP
Performance
Metrics
Couplings
 
 

PHPUK 2017
PHP TOKENS
[248] => Array
(
[0] => 382
[1] =>
[2] => 167
)
[249] => Array
(
[0] => 319
[1] => define
[2] => 167
)
[250] => (
[251] => Array
(
[0] => 323
[1] => 'EXT'
[2] => 167
)
[252] => ,
[253] => Array
(
[0] => 382
[1] =>
[2] => 167
)
‣ Comments, Doc, whitespace
‣ Delimiters : " () {} [] `
‣ 2/3 of the tokens are removed
<?php
//....
    define('EXT', '.php');
PHPUK 2017
AST
‣ PHP 7.0 : ext/ast
‣ nikic/php-parser
PHPUK 2017
AST
<?php
class Foo {
    function bar($arg) {
        return StrToUpper($arg + 2);
    }
}
$foo = new Foo();
$foo->bar(__FILE__);
TEXTE
<?php
    $x = source();
    
    if ($x < 10) {
        $y = $x + 1;
        $x = corrige($y);
    } else {
        $y = $x;
    }
FLOW CONTROL
TEXTE
FLOW CONTROL GRAPH
$x = source();
if ($x < 10) 
$y = $x + 1;
$x = corrige($y);
$y = $x;
PHP
Exit
Else
Then
<?php
    $x = source();
    
    if ($x < 10) {
        $y = $x + 1;
        $x = corrige($y);
    } else {
        $y = $x;
    }
PHPUK 2017
PROGRAM DEPENDENCY GRAPH
$x = source();
if ($x < 10) 
$y = $x + 1;
$x = corrige($y);
$y = $x;
Depend de $x
Depend de $x
Depend de $y
Depend de $x
Depend de $x
Depend de $x
<?php
    $x = source();
    
    if ($x < 10) {
        $y = $x + 1;
        $x = corrige($y);
    } else {
        $y = $x;
    }
PHPUK 2017
PHP AS A CODE DATABASE
‣ Source code is a highly organized dataset
‣ We need a way to query it
‣ There are over 68 static analysis tools for PHP
‣ https://github.com/exakat/php-static-analysis-tools
PHPUK 2017
STATIC ANALYSIS TOOLS
▸ Migration tools
▸ Code quality
▸ Security tools
▸ Metrics
▸ Inventories
PHPUK 2017
MIGRATION TOOLS
‣ Exakat
‣ php7mar
‣ php7cc
EXAKAT REPORT FOR PHP 7.2 COMPATIBILITY
PHPUK 2017
CODE QUALITY
‣ PHPstan
‣ Phan
‣ Psalm
‣ Exakat
PHPSTAN REPORT
------ --------------------------------------------- 

Line code/functions/scripts/pingCheck.php 

------ --------------------------------------------- 

362 Instantiated class phpipam_mail not found. 

415 Function create_link not found. 

446 Catched class phpmailerException not found. 

------ ------------------------------------ 

Line code/index.php 

------ ------------------------------------ 

228 Undefined variable: $heredoc 

------ ---------------------------------------- 

Line library/Exakat/Tasks/Files.php 

------ ---------------------------------------- 

197 Undefined variable: $toRemoveFromFiles 

------ ------------------------------------------------ 

Line code/functions/scripts/resolveIPaddresses.php 

------ ------------------------------------------------ 

236 Undefined variable: $returnPath 

[ERROR] Found 1846 errors
PHPUK 2017
SECURITY TOOLS
‣ psecio:parse
‣ php vuln hunter
‣ RIPS 0.5 / Ripstech saas
$x = source();
if ($x < 10) 
$y = $x + 1;
$x = corrige($y);
$y = $x;
Depend de $x
Depend de $x
Depend de $y
Depend de $x
Depend de $x
Depend de $x
PSECIO REPORT
55) projects/phpipam/code/app/dashboard/widgets/inactive-hosts.php on line 40

Avoid the use of $_REQUEST (know where your data comes from)

> if(!$widget = $Tools->fetch_object ("widgets", "wfile", $_REQUEST['section'])) { $Result->show(
For more information execute 'psecio-parse rules RequestUse'

296) functions/classes/class.Tools.php on line 2762

Avoid the use of `exit` or `die` with strings as it could lead to injection issues (direct output)

> $outFile = file_get_contents(dirname(__FILE__) . '/../../app/subnets/import-subnet/upload/i
upload/import.csv'), true));

For more information execute 'psecio-parse rules ExitOrDie'

448) index.php on line 284

'header()' calls should not use concatenation directly

> if (!in_array($_GET['section'], $tools_menu_items)) { header("Location:
For more information execute 'psecio-parse rules SetHeaderWithInput'
PHPUK 2017
METRICS
‣ PHP Metrics
‣ PHP MD
‣ PHP LOC
PHPMETRICS REPORT
PHPMETRICS REPORT
PHPUK 2017
INVENTORIES
‣ Collection of names, literals, feature
‣ Magic number syndrome
‣ PHP compilation directives
‣ Error messages check
‣ Spelling, consistency…
‣ Exakat
INVENTORY REPORT
PHP COMPILE SCRIPT
;;;;;;;;;;;;;;;;;;;;;;;;
; PHP configure list ;
;;;;;;;;;;;;;;;;;;;;;;;;
./configure
--with-apxs2
--enable-bcmath
--with-curl=DIR
--disable-dom
--enable-exif
--disable-fileinfo
--with-gd
--with-jpeg-dir=DIR
--with-png-dir=DIR
--with-xpm-dir=DIR
--with-vpx-dir=DIR
--with-freetype-dir=DIR
--enable-gd-native-ttf
--with-gettext=DIR
--with-gmp
--with-ldap[=DIR]
--with-ldap-sasl[=DIR]
--disable-libxml
--enable-mbstring
--with-libmbfl=DIR
--enable-mbstr-enc-trans
--disable-mbregex
--with-mcrypt=[DIR]
; Duration of time (in seconds) for which to cache realpath information
; given file or directory. If the application's code doesn't change too o
; may set this directive to 3600 (one hour) or even more.
realpath_cache_ttl = 3600
; More information about file :
;http://php.net/manual/en/filesystem.configuration.php
[File Upload]
; This is the maximum uploaded size. It is recommended to keep this
; as possible.
upload_max_filesize = 2M
; This is the maximum number of uploaded files in a single request.
max_file_uploads = 1
; Upload directory where PHP stores the temporary files. It is recomm
; this value, and separate it from other temporary directories.
upload_tmp_dir = /tmp/php_upload
; This is the maximum amount of data that PHP will accept in a POST r
; has to be higher or equal to upload_max_filesize. For security reason
; should be as low as possible, to prevent PHP using too much memo
post_max_size = 2M
PHP DIRECTIVES CHECKLIST
PHPUK 2017
OTHER USAGE
▸ Dependency graph
▸ Namespaces graph
▸ Deptrack
▸ Taint analysis
Static analysis saved my code tonight
PHPUK 2017
WRITE YOUR OWN STATIC ANALYSER
▸ ext/ast : Access the internal AST
▸ nikic/php-parser : for PHP 7
▸ BetterReflection
▸ Fork an existing tool
▸ Use regex
PHPUK 2017
MORE IDEAS
▸ Static analysis for frameworks
▸ Class diagram extractors
▸ Definition / usage paradigm
▸ More coding references
▸ East-programming, SOLID
▸ ~40% of PHP code is static
TEXTE
NEVER CODE ALONE AGAIN
▸ Use experience from others
▸ Use some one else point of view
▸ Prepare for the future
▸ Learn, Find, Capitalize
THANKS
@EXAKAT / EXAKAT.IO

More Related Content

PDF
Sipwise rtpengine
PDF
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
PDF
rtpengine and kamailio - or how to simulate calls at scale
PDF
rtpengine - Media Relaying and Beyond
PDF
SIP Tutorial/Workshop 2
PDF
SIP Tutorial/Workshop 3
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
PDF
SIP Tutorial/Workshop 4
Sipwise rtpengine
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
rtpengine and kamailio - or how to simulate calls at scale
rtpengine - Media Relaying and Beyond
SIP Tutorial/Workshop 2
SIP Tutorial/Workshop 3
Beyond Breakpoints: A Tour of Dynamic Analysis
SIP Tutorial/Workshop 4

What's hot (9)

PDF
No REST - Architecting Real-time Bulk Async APIs
ODP
Nginx monitoring with graphite
PDF
マイクロサービスバックエンドAPIのためのRESTとgRPC
DOCX
CCNP Quizzes
PDF
SIP Tutorial/Workshop 1
PPTX
Failing at Scale - PNWPHP 2016
PDF
nextcomputing-cyberpro
PPTX
Docker for Developers - PNWPHP 2016 Workshop
PDF
OSMC 2018 | Distributed Tracing FAQ by Gianluca Arbezzano
No REST - Architecting Real-time Bulk Async APIs
Nginx monitoring with graphite
マイクロサービスバックエンドAPIのためのRESTとgRPC
CCNP Quizzes
SIP Tutorial/Workshop 1
Failing at Scale - PNWPHP 2016
nextcomputing-cyberpro
Docker for Developers - PNWPHP 2016 Workshop
OSMC 2018 | Distributed Tracing FAQ by Gianluca Arbezzano
Ad

Viewers also liked (20)

PDF
Php in the graph (Gremlin 3)
PDF
Review unknown code with static analysis - bredaphp
PDF
當六脈神劍遇上 PhpStorm
PDF
Php 7.2 compliance workshop php benelux
PDF
Hunt for dead code
PDF
php & performance
PDF
Google Analytics Campaign Tracking Fundamentals
PDF
Last train to php 7
PDF
Rasmus, Think Again! Agile Framework == Happy Php Developer
PDF
BSides Algiers - PHP Static Code Analysis - Abdeldjalil Belakhdar
ODP
Spaghetti Code vs MVC
PDF
How to stop writing spaghetti code
PDF
RIPS - static code analyzer for vulnerabilities in PHP
PDF
Introduction to Using PHP & MVC Frameworks
PPTX
Modern Static Code Analysis in PHP
PPT
Night of the Long Knives
PDF
Machine learning in php php con poland
PDF
Machine learning in php
PDF
Php performance-talk
PPT
S3 Overview Presentation
Php in the graph (Gremlin 3)
Review unknown code with static analysis - bredaphp
當六脈神劍遇上 PhpStorm
Php 7.2 compliance workshop php benelux
Hunt for dead code
php & performance
Google Analytics Campaign Tracking Fundamentals
Last train to php 7
Rasmus, Think Again! Agile Framework == Happy Php Developer
BSides Algiers - PHP Static Code Analysis - Abdeldjalil Belakhdar
Spaghetti Code vs MVC
How to stop writing spaghetti code
RIPS - static code analyzer for vulnerabilities in PHP
Introduction to Using PHP & MVC Frameworks
Modern Static Code Analysis in PHP
Night of the Long Knives
Machine learning in php php con poland
Machine learning in php
Php performance-talk
S3 Overview Presentation
Ad

Similar to Static analysis saved my code tonight (20)

PDF
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
PDF
Static analysis saved my code tonight
PDF
20 PHP Static Analysis and Documentation Generators #burningkeyboards
KEY
Prepare for PHP Test Fest 2009
PDF
Running PHP on Nginx
PDF
Running PHP on nginx
ODP
Award-winning technology: Oxid loves the query cache
PDF
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PDF
Php through the eyes of a hoster phpbnl11
PDF
PHP QA Tools
ODP
Sonar - the ring to rule them all
KEY
Movable Type 5.2 Overview at MTDDC 2012
PDF
Php through the eyes of a hoster
PDF
Last 2 Months in PHP - July & August 2016
PDF
PHP & Performance
PDF
PHP Development Tools
PDF
PDF
What We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
PDF
Nginx pres
PDF
10 Million hits a day with WordPress using a $15 VPS
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
Static analysis saved my code tonight
20 PHP Static Analysis and Documentation Generators #burningkeyboards
Prepare for PHP Test Fest 2009
Running PHP on Nginx
Running PHP on nginx
Award-winning technology: Oxid loves the query cache
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
Php through the eyes of a hoster phpbnl11
PHP QA Tools
Sonar - the ring to rule them all
Movable Type 5.2 Overview at MTDDC 2012
Php through the eyes of a hoster
Last 2 Months in PHP - July & August 2016
PHP & Performance
PHP Development Tools
What We Learned Building an R-Python Hybrid Predictive Analytics Pipeline
Nginx pres
10 Million hits a day with WordPress using a $15 VPS

More from Damien Seguy (20)

PDF
Strong typing @ php leeds
PPTX
Strong typing : adoption, adaptation and organisation
PDF
Qui a laissé son mot de passe dans le code
PDF
Analyse statique et applications
PDF
Top 10 pieges php afup limoges
PDF
Top 10 php classic traps DPC 2020
PDF
Meilleur du typage fort (AFUP Day, 2020)
PDF
Top 10 php classic traps confoo
PDF
Tout pour se préparer à PHP 7.4
PDF
Top 10 php classic traps php serbia
PDF
Top 10 php classic traps
PDF
Top 10 chausse trappes
PDF
Code review workshop
PDF
Understanding static analysis php amsterdam 2018
PDF
Review unknown code with static analysis php ce 2018
PDF
Everything new with PHP 7.3
PDF
Php 7.3 et ses RFC (AFUP Toulouse)
PDF
Tout sur PHP 7.3 et ses RFC
PDF
Review unknown code with static analysis php ipc 2018
PDF
Code review for busy people
Strong typing @ php leeds
Strong typing : adoption, adaptation and organisation
Qui a laissé son mot de passe dans le code
Analyse statique et applications
Top 10 pieges php afup limoges
Top 10 php classic traps DPC 2020
Meilleur du typage fort (AFUP Day, 2020)
Top 10 php classic traps confoo
Tout pour se préparer à PHP 7.4
Top 10 php classic traps php serbia
Top 10 php classic traps
Top 10 chausse trappes
Code review workshop
Understanding static analysis php amsterdam 2018
Review unknown code with static analysis php ce 2018
Everything new with PHP 7.3
Php 7.3 et ses RFC (AFUP Toulouse)
Tout sur PHP 7.3 et ses RFC
Review unknown code with static analysis php ipc 2018
Code review for busy people

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
project resource management chapter-09.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPT
What is a Computer? Input Devices /output devices
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Architecture types and enterprise applications.pdf
PPTX
Chapter 5: Probability Theory and Statistics
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Univ-Connecticut-ChatGPT-Presentaion.pdf
DP Operators-handbook-extract for the Mautical Institute
A contest of sentiment analysis: k-nearest neighbor versus neural network
Zenith AI: Advanced Artificial Intelligence
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
project resource management chapter-09.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
O2C Customer Invoices to Receipt V15A.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
WOOl fibre morphology and structure.pdf for textiles
What is a Computer? Input Devices /output devices
Group 1 Presentation -Planning and Decision Making .pptx
1. Introduction to Computer Programming.pptx
Final SEM Unit 1 for mit wpu at pune .pptx
cloud_computing_Infrastucture_as_cloud_p
OMC Textile Division Presentation 2021.pptx
Architecture types and enterprise applications.pdf
Chapter 5: Probability Theory and Statistics

Static analysis saved my code tonight

  • 1. STATIC ANALYSIS SAVED MY CODE TONIGHT PHP UK, LONDON, FEBRUARY 2017.
  • 2. PHPUK 2017 AGENDA ‣ Under the hood of a static analyzer ‣ What can analyzers do for you ‣ Adopt them now!
  • 3. ‣ Damien Seguy ‣ CTO at exakat ‣ Static code analysis for PHP ‣ Retiring house for oldest 
 elephpant PHPUK 2017 SPEAKER Elephpant in the death valley
  • 4. ‣ IS IT FAST? ‣ IS THIS BACKWARD COMPATIBLE? ‣ IS THIS SECURE? ‣ IS THIS COMPATIBLE WITH PHP 7? ‣ SHOULD I USE ++$I OR ARRAY_MERGE_RECURSIVE() ? ‣ IS IT TIME FOR LUNCH ? ‣ WHY NOT USE A FRAMEWORK?
  • 5. PHPUK 2017 STATIC ANALYSIS IS AN EXTRA STEP EXECUTION TEXT FILE OPCODE CODING CONVENTIONS
  • 6. PHPUK 2017 STATIC ANALYSIS IS AN EXTRA STEP EXECUTION TEXT FILE OPCODE STATIC ANALYSIS
  • 7. OPCODE PHPUK 2017 STATIC ANALYSIS IS AN EXTRA STEP EXECUTION TEXT FILE STATIC ANALYSIS
  • 8. PHPUK 2017 SWITCH STATEMENTS MAY ONLY CONTAIN ONE DEFAULT CLAUSE <?php    switch($x) {        case '1' :             break;        default :             break;        default :             break;        case '2' :             break;    }    PHP Lint
  • 9. PHPUK 2017 SWITCH STATEMENTS MAY ONLY CONTAIN ONE DEFAULT CLAUSE switch($x) {        case 1 :             break;        case 0+1 :             break;        case '1' :             break;        case true :             break;        case 1.0 :             break;        case $y :             break;    }   
  • 10. PHPUK 2017 STATIC ANALYSIS UNDER THE HOOD PHP 5 / 7 Calisthenics ClearPHP Performance Metrics Couplings     
  • 11. PHPUK 2017 PHP TOKENS [248] => Array ( [0] => 382 [1] => [2] => 167 ) [249] => Array ( [0] => 319 [1] => define [2] => 167 ) [250] => ( [251] => Array ( [0] => 323 [1] => 'EXT' [2] => 167 ) [252] => , [253] => Array ( [0] => 382 [1] => [2] => 167 ) ‣ Comments, Doc, whitespace ‣ Delimiters : " () {} [] ` ‣ 2/3 of the tokens are removed <?php //....     define('EXT', '.php');
  • 12. PHPUK 2017 AST ‣ PHP 7.0 : ext/ast ‣ nikic/php-parser
  • 16. PHPUK 2017 PROGRAM DEPENDENCY GRAPH $x = source(); if ($x < 10)  $y = $x + 1; $x = corrige($y); $y = $x; Depend de $x Depend de $x Depend de $y Depend de $x Depend de $x Depend de $x <?php     $x = source();          if ($x < 10) {         $y = $x + 1;         $x = corrige($y);     } else {         $y = $x;     }
  • 17. PHPUK 2017 PHP AS A CODE DATABASE ‣ Source code is a highly organized dataset ‣ We need a way to query it ‣ There are over 68 static analysis tools for PHP ‣ https://github.com/exakat/php-static-analysis-tools
  • 18. PHPUK 2017 STATIC ANALYSIS TOOLS ▸ Migration tools ▸ Code quality ▸ Security tools ▸ Metrics ▸ Inventories
  • 19. PHPUK 2017 MIGRATION TOOLS ‣ Exakat ‣ php7mar ‣ php7cc
  • 20. EXAKAT REPORT FOR PHP 7.2 COMPATIBILITY
  • 21. PHPUK 2017 CODE QUALITY ‣ PHPstan ‣ Phan ‣ Psalm ‣ Exakat
  • 22. PHPSTAN REPORT ------ --------------------------------------------- Line code/functions/scripts/pingCheck.php ------ --------------------------------------------- 362 Instantiated class phpipam_mail not found. 415 Function create_link not found. 446 Catched class phpmailerException not found. ------ ------------------------------------ Line code/index.php ------ ------------------------------------ 228 Undefined variable: $heredoc ------ ---------------------------------------- Line library/Exakat/Tasks/Files.php ------ ---------------------------------------- 197 Undefined variable: $toRemoveFromFiles ------ ------------------------------------------------ Line code/functions/scripts/resolveIPaddresses.php ------ ------------------------------------------------ 236 Undefined variable: $returnPath [ERROR] Found 1846 errors
  • 23. PHPUK 2017 SECURITY TOOLS ‣ psecio:parse ‣ php vuln hunter ‣ RIPS 0.5 / Ripstech saas $x = source(); if ($x < 10)  $y = $x + 1; $x = corrige($y); $y = $x; Depend de $x Depend de $x Depend de $y Depend de $x Depend de $x Depend de $x
  • 24. PSECIO REPORT 55) projects/phpipam/code/app/dashboard/widgets/inactive-hosts.php on line 40 Avoid the use of $_REQUEST (know where your data comes from) > if(!$widget = $Tools->fetch_object ("widgets", "wfile", $_REQUEST['section'])) { $Result->show( For more information execute 'psecio-parse rules RequestUse' 296) functions/classes/class.Tools.php on line 2762 Avoid the use of `exit` or `die` with strings as it could lead to injection issues (direct output) > $outFile = file_get_contents(dirname(__FILE__) . '/../../app/subnets/import-subnet/upload/i upload/import.csv'), true)); For more information execute 'psecio-parse rules ExitOrDie' 448) index.php on line 284 'header()' calls should not use concatenation directly > if (!in_array($_GET['section'], $tools_menu_items)) { header("Location: For more information execute 'psecio-parse rules SetHeaderWithInput'
  • 25. PHPUK 2017 METRICS ‣ PHP Metrics ‣ PHP MD ‣ PHP LOC
  • 28. PHPUK 2017 INVENTORIES ‣ Collection of names, literals, feature ‣ Magic number syndrome ‣ PHP compilation directives ‣ Error messages check ‣ Spelling, consistency… ‣ Exakat
  • 30. PHP COMPILE SCRIPT ;;;;;;;;;;;;;;;;;;;;;;;; ; PHP configure list ; ;;;;;;;;;;;;;;;;;;;;;;;; ./configure --with-apxs2 --enable-bcmath --with-curl=DIR --disable-dom --enable-exif --disable-fileinfo --with-gd --with-jpeg-dir=DIR --with-png-dir=DIR --with-xpm-dir=DIR --with-vpx-dir=DIR --with-freetype-dir=DIR --enable-gd-native-ttf --with-gettext=DIR --with-gmp --with-ldap[=DIR] --with-ldap-sasl[=DIR] --disable-libxml --enable-mbstring --with-libmbfl=DIR --enable-mbstr-enc-trans --disable-mbregex --with-mcrypt=[DIR] ; Duration of time (in seconds) for which to cache realpath information ; given file or directory. If the application's code doesn't change too o ; may set this directive to 3600 (one hour) or even more. realpath_cache_ttl = 3600 ; More information about file : ;http://php.net/manual/en/filesystem.configuration.php [File Upload] ; This is the maximum uploaded size. It is recommended to keep this ; as possible. upload_max_filesize = 2M ; This is the maximum number of uploaded files in a single request. max_file_uploads = 1 ; Upload directory where PHP stores the temporary files. It is recomm ; this value, and separate it from other temporary directories. upload_tmp_dir = /tmp/php_upload ; This is the maximum amount of data that PHP will accept in a POST r ; has to be higher or equal to upload_max_filesize. For security reason ; should be as low as possible, to prevent PHP using too much memo post_max_size = 2M PHP DIRECTIVES CHECKLIST
  • 31. PHPUK 2017 OTHER USAGE ▸ Dependency graph ▸ Namespaces graph ▸ Deptrack ▸ Taint analysis
  • 33. PHPUK 2017 WRITE YOUR OWN STATIC ANALYSER ▸ ext/ast : Access the internal AST ▸ nikic/php-parser : for PHP 7 ▸ BetterReflection ▸ Fork an existing tool ▸ Use regex
  • 34. PHPUK 2017 MORE IDEAS ▸ Static analysis for frameworks ▸ Class diagram extractors ▸ Definition / usage paradigm ▸ More coding references ▸ East-programming, SOLID ▸ ~40% of PHP code is static
  • 35. TEXTE NEVER CODE ALONE AGAIN ▸ Use experience from others ▸ Use some one else point of view ▸ Prepare for the future ▸ Learn, Find, Capitalize