SlideShare a Scribd company logo
Let’s write secure Drupal code!
Balazs Janos Tatar
DrupalCamp Oslo 2018
Thanks Sponsors!
Who am I?
Tatar Balazs Janos
@tatarbj
Hungarian, lives in Brussels
Works with Drupal since 2007
Provisional Member of Drupal Security Team
IT Security Analyst, Drupal Security
Correspondent @ EC... And a cat-gif addict
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Are there site builders?
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Demo
Gist
http://bit.ly/oslo_writes_secure_drupal_code
Are there developers/maintainers?
Trends in Security
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Types of vulnerabilities
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Cross Site Scripting
Client side vulnerability
Unfiltered output
Never trust any user input.
We’ve seen the demo before ;)
Cross Site Scripting
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Html::escape() – plain text
Xss::filter() – html is allowed
Xss::filterAdmin() – text by admins
Test
Raise your green card if snippet is secure!
Raise your red card if code has issues!
<?php print '<tr><td>' . check_plain($title) . '</td></tr>'; ?>
<?php print '<tr><td>' . check_plain($title) . '</td></tr>'; ?>
<?php print '<a href="/' . check_plain($url) . '">'; ?>
<?php print '<a href="/' . check_plain($url) . '">'; ?>
<?php print '<a href="/' . check_url($url) . '">'; ?>
foreach ($items as $delta => $item) {
$id = $item->getValue()['target_id'];
$content = Drupal::entityTypeManager()
->getStorage($entity_type_id)
->load($id);
$body = $content->get('body_field')->getValue()[0]['value'];
}
$elements[$delta] = array(
'#theme' => 'something_custom',
'#body' => $body,
);
return $elements;
foreach ($items as $delta => $item) {
$id = $item->getValue()['target_id'];
$content = Drupal::entityTypeManager()
->getStorage($entity_type_id)
->load($id);
$body = $content->get('body_field')->getValue()[0]['value'];
}
$elements[$delta] = array(
'#theme' => 'something_custom',
'#body' => $body,
);
return $elements;
foreach ($items as $delta => $item) {
$id = $item->getValue()['target_id'];
$content = Drupal::entityTypeManager()
->getStorage($entity_type_id)
->load($id);
$body = [
'#type' => 'processed_text',
'#text' => $content->get('body_field')->getValue()[0]['value'],
'#format' => $content->get('body_field')->getValue()[0]['format'], ];
}
$elements[$delta] = array(
'#theme' => 'something_custom',
'#body' => $body,
);
return $elements;
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Use behat/automated tests.
<script>alert(‘XSS’)</script>
<img src=“a” onerror=“alert(’title’)”>
Check your filters and user roles.
Do not give too many options to
untrusted users!
Protection against Cross Site Scripting
Access Bypass
User can access/do something.
Menu items can be defined to be
accessed/denied.
Many access systems: node, entity,
field, views...
Access bypass
Test II.
<?php
function mymodule_menu() {
$items['admin/mymodule/settings'] = array(
'title' => 'Settings of my module',
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_setting_form'),
'access arguments' => array('administer mymodule'),
'type' => MENU_LOCAL_ACTION,
);
return $items;
}
?>
<?php
function mymodule_menu() {
$items['admin/mymodule/settings'] = array(
'title' => 'Settings of my module',
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_setting_form'),
'access arguments' => array('administer mymodule'),
'type' => MENU_LOCAL_ACTION,
);
return $items;
}
?>
<?php
$query = db_select('node', 'n')
->fields('n', array('title', 'nid')
->condition('type', 'article');
$result = $query->execute();
?>
<?php
$query = db_select('node', 'n')
->fields('n', array('title', 'nid')
->condition('type', 'article');
$result = $query->execute();
?>
<?php
$query = db_select('node', 'n')
->fields('n', array('title', 'nid')
->condition('type', 'article')
->addTag('node_access');
$result = $query->execute();
?>
mymodule.not_found:
path: '/not-found'
defaults:
_controller: DrupalmymoduleControllerNotFoundController::build404
_title: 'Page not found'
requirements:
_access: 'TRUE'
mymodule.not_found:
path: '/not-found'
defaults:
_controller: DrupalmymoduleControllerNotFoundController::build404'
_title: 'Page not found'
requirements:
_access: 'TRUE'
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Visit node/nid and other urls
Visit anything/%node
Use behat/automated tests.
node_access, entity_access
Menu definitions
user_access for permissions
$query->addTag('node_access')
Protection against Access bypass
SQL Injection
Unauthorized access to database
resources.
Do not trust any user input.
SA-CORE-2014-005 – Highly critical D7
SA
SQL Injection
Test III.
<?php
$results = db_query("SELECT uid, name, mail FROM {users}
WHERE name LIKE '%%$user_search%%'");
?>
<?php
$results = db_query("SELECT uid, name, mail FROM {users}
WHERE name LIKE '%%$user_search%%'");
?>
<?php
$results = db_query("SELECT uid, name, mail FROM {users}
WHERE name LIKE :user_search",
array(':user_search' => '%' . db_like($user_search)));
?>
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Use always drupal Database API!
db_query with :placeholder (deprecated in D8, in D9 will
be removed)
Filter parameters
Check the queries in code.
username' AND 1=1
POST requests by curl
Protection against SQL Injection
Security Improvements
*https://events.drupal.org/sites/default/files/slides/pwolanin-2017-09-ways-drupal8-d.pdf
Many ways Drupal 8 is more secure!
Twig templates for HTML generation
Removed PHP format
Site configuration exportable, versionable
User content entry and filtering improvements
User session and sessio always n ID handling
Automated CSRF token protection
Trusted host patterns enforced for requests
Single statement execution for SQL
Clickjacking protection
Content security policy compatibility with Core Javascript API
Learn by Advisories
Security advisories are for
Only stable modules
No alpha, beta, dev
d.org hosted modules
@Maintainers: If you are contacted, be supportive! .
Drupal Security Team
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Hacked!
Security review (simplytest.me)
Password policy
Encrypt
Drop Guard
Composer Security Checker
Permission report
Text format reported
+ PHPCS Drupal BestPractice Sniff
Security related contribs
Questions?
Tatar Balazs Janos
@tatarbj
Thank you!

More Related Content

What's hot (20)

PDF
Doctrine 2
zfconfua
 
PPTX
Let's write secure Drupal code! - DrupalCamp Belarus 2019
Balázs Tatár
 
PDF
Drupal 8: Routing & More
drubb
 
PDF
Building Lithium Apps
Nate Abele
 
PDF
SPL: The Missing Link in Development
jsmith92
 
PDF
The Origin of Lithium
Nate Abele
 
PPT
Php My Sql
mussawir20
 
PPTX
Introduction to PHP Lecture 1
Ajay Khatri
 
PDF
WCLV13 JavaScript
Jeffrey Zinn
 
PPT
Intro to php
Sp Singh
 
PPT
Ubi comp27nov04
mohamed ashraf
 
PDF
Shortcodes In-Depth
Micah Wood
 
PPTX
Jquery introduction
musrath mohammad
 
PDF
Django - 次の一歩 gumiStudy#3
makoto tsuyuki
 
KEY
Apache Velocity 1.6
Henning Schmiedehausen
 
KEY
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
PPT
Propel sfugmd
iKlaus
 
PDF
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Labs
 
PPTX
Basics of Java Script (JS)
Ajay Khatri
 
PDF
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
Doctrine 2
zfconfua
 
Let's write secure Drupal code! - DrupalCamp Belarus 2019
Balázs Tatár
 
Drupal 8: Routing & More
drubb
 
Building Lithium Apps
Nate Abele
 
SPL: The Missing Link in Development
jsmith92
 
The Origin of Lithium
Nate Abele
 
Php My Sql
mussawir20
 
Introduction to PHP Lecture 1
Ajay Khatri
 
WCLV13 JavaScript
Jeffrey Zinn
 
Intro to php
Sp Singh
 
Ubi comp27nov04
mohamed ashraf
 
Shortcodes In-Depth
Micah Wood
 
Jquery introduction
musrath mohammad
 
Django - 次の一歩 gumiStudy#3
makoto tsuyuki
 
Apache Velocity 1.6
Henning Schmiedehausen
 
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
Propel sfugmd
iKlaus
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Labs
 
Basics of Java Script (JS)
Ajay Khatri
 
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 

Similar to Let's write secure Drupal code! - DrupalCamp Oslo, 2018 (20)

PPTX
Let's write secure drupal code!
Balázs Tatár
 
PPTX
Let's write secure Drupal code! - DrupalCamp London 2019
Balázs Tatár
 
PDF
Mojolicious
Marcos Rebelo
 
PDF
Broadleaf Presents Thymeleaf
Broadleaf Commerce
 
PDF
Separation of concerns - DPC12
Stephan Hochdörfer
 
PPTX
Let's write secure Drupal code! Drupal MountainCamp 2019
Balázs Tatár
 
PPTX
Let's write secure Drupal code! - DrupalCamp Spain 2019
Balázs Tatár
 
PDF
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
camp_drupal_ua
 
KEY
Zend Framework Study@Tokyo #2
Shinya Ohyanagi
 
PPTX
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
DrupalCamp Kyiv
 
PDF
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
 
PDF
Internationalizing CakePHP Applications
Pierre MARTIN
 
PDF
Virtual Madness @ Etsy
Nishan Subedi
 
PDF
R57shell
ady36
 
PDF
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 
PDF
Your Entity, Your Code
Marco Vito Moscaritolo
 
PDF
Your Entity, Your Code
DrupalDay
 
PDF
Bag Of Tricks From Iusethis
Marcus Ramberg
 
PPTX
Open Source Search: An Analysis
Justin Finkelstein
 
PDF
Mojolicious, real-time web framework
taggg
 
Let's write secure drupal code!
Balázs Tatár
 
Let's write secure Drupal code! - DrupalCamp London 2019
Balázs Tatár
 
Mojolicious
Marcos Rebelo
 
Broadleaf Presents Thymeleaf
Broadleaf Commerce
 
Separation of concerns - DPC12
Stephan Hochdörfer
 
Let's write secure Drupal code! Drupal MountainCamp 2019
Balázs Tatár
 
Let's write secure Drupal code! - DrupalCamp Spain 2019
Balázs Tatár
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
camp_drupal_ua
 
Zend Framework Study@Tokyo #2
Shinya Ohyanagi
 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
DrupalCamp Kyiv
 
Practical PHP by example Jan Leth-Kjaer
COMMON Europe
 
Internationalizing CakePHP Applications
Pierre MARTIN
 
Virtual Madness @ Etsy
Nishan Subedi
 
R57shell
ady36
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 
Your Entity, Your Code
Marco Vito Moscaritolo
 
Your Entity, Your Code
DrupalDay
 
Bag Of Tricks From Iusethis
Marcus Ramberg
 
Open Source Search: An Analysis
Justin Finkelstein
 
Mojolicious, real-time web framework
taggg
 
Ad

More from Balázs Tatár (16)

PPTX
How To Have Fun in Open Source - CMS Garden Unconference 2019
Balázs Tatár
 
PPTX
Software Development Weaknesses - SecOSdays Sofia, 2019
Balázs Tatár
 
PPTX
Security Awareness for Open Source Web Applications
Balázs Tatár
 
PPTX
A bug's life - Decoupled Drupal Security and Vulnerability Management
Balázs Tatár
 
PPTX
A bug's life - Drupal Application Security and Vulnerability Management
Balázs Tatár
 
PPTX
A bug's life - Drupal Application Security and Vulnerability Management
Balázs Tatár
 
PPTX
Let's write secure Drupal code! - DrupalCamp Kyiv 2019
Balázs Tatár
 
PPT
DrupalCon Seattle 2019 - Mentoring Booth slides
Balázs Tatár
 
PPTX
Everything You Always Wanted to Know About Drupal Security* (*But Were Afraid...
Balázs Tatár
 
PPTX
Everything You Always Wanted to Know About Drupal Security (*But Were Afraid ...
Balázs Tatár
 
PDF
Mentoring slides - Drupal Europe, Darmstadt, Germany 2018
Balázs Tatár
 
PDF
Quality assurance in practice
Balázs Tatár
 
PPTX
Quality assurance in practice - coffee meeting, January, DIGIT
Balázs Tatár
 
PPTX
Quality assurance in practice - brussels drupal meetup
Balázs Tatár
 
PPTX
Quality assurance in practice
Balázs Tatár
 
PPT
Drupal 7 - Form API
Balázs Tatár
 
How To Have Fun in Open Source - CMS Garden Unconference 2019
Balázs Tatár
 
Software Development Weaknesses - SecOSdays Sofia, 2019
Balázs Tatár
 
Security Awareness for Open Source Web Applications
Balázs Tatár
 
A bug's life - Decoupled Drupal Security and Vulnerability Management
Balázs Tatár
 
A bug's life - Drupal Application Security and Vulnerability Management
Balázs Tatár
 
A bug's life - Drupal Application Security and Vulnerability Management
Balázs Tatár
 
Let's write secure Drupal code! - DrupalCamp Kyiv 2019
Balázs Tatár
 
DrupalCon Seattle 2019 - Mentoring Booth slides
Balázs Tatár
 
Everything You Always Wanted to Know About Drupal Security* (*But Were Afraid...
Balázs Tatár
 
Everything You Always Wanted to Know About Drupal Security (*But Were Afraid ...
Balázs Tatár
 
Mentoring slides - Drupal Europe, Darmstadt, Germany 2018
Balázs Tatár
 
Quality assurance in practice
Balázs Tatár
 
Quality assurance in practice - coffee meeting, January, DIGIT
Balázs Tatár
 
Quality assurance in practice - brussels drupal meetup
Balázs Tatár
 
Quality assurance in practice
Balázs Tatár
 
Drupal 7 - Form API
Balázs Tatár
 
Ad

Recently uploaded (20)

PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 

Let's write secure Drupal code! - DrupalCamp Oslo, 2018