Drupal Security:
What You Need to Know
March 25, 2021
The
Open Source Expansion
Partner
Our vision is to empower every person on
the planet with the innovative freedom
and community impact that open-source
technology offers.
Our Vision
Today’s
Team
Mark Shropshire
Senior Director of Development
Bobby Gryzynger
Senior Developer
Bobby Gryzynger
Senior Developer
/in/bobby-gryzynger
● From Madison, Wisconsin. Currently in northern NJ
● 5+ years of experience as a Drupal developer
● Enjoys contributing to Drupal development. Has
committed work in several contributed modules
as well as Drupal core
● Breakfast chef. French toast? Pancakes? I’m your
man
Skills
● Drupal
● Security
● DevOps
● Project Leadership
● Drupal best-
practices
Mark Shropshire
Senior Director of Development
/in/markshropshire
@shrop
● From Concord, North Carolina
● 20+ years of experience as a technical team leader
● Loves empowering teams to excel while using
best of class open source technology solutions.
● Passionate about personal and team growth
through mentorship, aligning individual purpose
with Mediacurrent’s vision
● Plays sax, drums, keys, and bass and has a list of
other instruments that he would love to learn!
Skills
● Drupal
● Security
● DevOps
● Flutter
● Acquia Site Factory
● Leadership
1. What’s Security-First?
2. Security and The Drupal Community
3. OWASP Top 10 Web Vulnerabilities
4. Drupal Best Practices
5. Q&A
Today’s
Agenda
What’s Security-First?
Security-First means going beyond compliance
to assess risk. It’s both a cultural mindset and a
continuous development approach that’s
rooted in process automation.
Security-First
Planning
● Proactive and collaborative
approach with stakeholders
● Layered defense
● Architecture reviews
● Code reviews
● Automated testing
● Continuous improvements
● Security audits (one-offs and
ongoing)
● Documentation
Security and The
Drupal Community
Drupal Security Team
● Resolves reported security issues in Security Advisories
● Provides assistance for contributed module maintainers
in resolving security issues
● Provides documentation on how to write secure code
● Provides documentation on securing your site
● Help the infrastructure team to keep the drupal.org
secure
● https://www.drupal.org/security-team
Guardr is a Drupal distribution with a
combination of modules and settings to
enhance a Drupal application's security
and availability to meet enterprise
security requirements.
Guardr incorporates industry best
practices from security standards,
regulatory controls, and security
certifications.
https://drupal.org/project/guardr
Drupal Slack: #contrib-guardr
OWASP Top 10 Web
Vulnerabilities
| 15
Top 10 Web Application
Security Risks
Injection
Broken Authentication
Sensitive Data Exposure
XML External Entities (XXE)
Broken Access Control
Security Misconfiguration
Cross-Site Scripting XSS
Insecure Deserialization
Using Components with Known Vulnerabilities
Insufficient Logging & Monitoring
https://owasp.org/www-project-top-ten
Drupal Best Practices
Module
Selection
● Module Usage
● Issue Queue Activity
● Security
● Manual Review and Testing
● Release Status
● Commit Activity
● Project information
● Risk Assessment
● Benefit
A Guide to Drupal Module Evaluation
Module
patches
● Sometimes, patches are
necessary
● Always submit patches to
Drupal.org
● Submitting patches allows:
○ Automated testing
○ Maintainer review
● Patches create:
○ Revision history
○ An opportunity for
community input
Use Drupal APIs
Use Drupal APIs to secure your contrib and custom code.
https://api.drupal.org/api/drupal
Writing secure code for Drupal
| 20
// Uh, oh: $my_var = "<script>alert('Attack!')</script>";
Not This:
$variables['title'] = "Here's a title: " . $my_var;
Instead, this:
$variables['title'] = t("Here's a title: @title", ['@title' => $my_var]);
Also see
Drupal::translation()->formatPlural()
t()
| 21
// Uh, oh: $my_var = "<script>alert('Attack!')</script>";
// Oh, no: $my_other_var = "<div>some unexpected HTML</div>";
Not This:
$variables['title'] = '<p>' . $my_var . '</p>';
$variables['body'] = $node->get('body')->value . $my_other_var;
Instead, this:
$variables['title'] = Xss::filter($my_var);
$variables['body'] = $node->get('body')->value . Html::escape($my_other_var);
Xss::filter() and Html::escape()
| 22
Monitor Drupal
Security Advisories
● Drupal core
● Drupal contrib projects
● Public service announcements
● Notifications via email and RSS
● Follow @drupalsecurity on Twitter
● Drupal Slack #security-questions
● Read SA documentation
https://www.drupal.org/security
| 23
// Uh, oh: $my_var = ", (SELECT * FROM private_data) as attack";
Not this:
Drupal::database()->query('SELECT * FROM node_field_data ' . $my_var);
Instead, this:
// Better.
Drupal::database()
->select('node_field_data', 'd')
->fields('d', [])
->condition('d.nid', $my_var);
Drupal:database()
// Better yet.
Drupal::entityTypeManager()-getStorage('node')
->getQuery()
->condition('nid', $my_var);
| 24
Not this:
public function myControllerBuild($nid) {
// ...
$node = $this->entityTypeManager()
->getStorage('node')->load($nid);
// ...
$build['node'] = $node->view();
return $build;
}
Controllers
Instead, this:
public function myControllerBuild($nid) {
// ...
$node = $this->entityTypeManager()
->getStorage('node')->load($nid);
// ...
if($node->access('view', $this->currentUser)) {
$build['node'] = $node->view();
}
return $build;
}
| 25
Secure your open source-based
martech stack with this resource
for best practices.
http://bit.ly/open-source-security
Download Now
CMO’s Guide
to Open Source
Security
| 26
Key Takeaways
Cultivate a security-first culture.
Educate yourself on security risks that can impact your organization.
Review and monitor Drupal security advisories.
Follow Drupal best practices.
Automate security processes.
Promptly update security releases.
@Mediacurrent
Mediacurrent @Mediacurrent
MediacurrentDrupal
Mediacurrent.com
@Mediacurrent
Thank You!

Drupal Security: What You Need to Know

  • 1.
    Drupal Security: What YouNeed to Know March 25, 2021
  • 2.
  • 3.
    Our vision isto empower every person on the planet with the innovative freedom and community impact that open-source technology offers. Our Vision
  • 4.
    Today’s Team Mark Shropshire Senior Directorof Development Bobby Gryzynger Senior Developer
  • 5.
    Bobby Gryzynger Senior Developer /in/bobby-gryzynger ●From Madison, Wisconsin. Currently in northern NJ ● 5+ years of experience as a Drupal developer ● Enjoys contributing to Drupal development. Has committed work in several contributed modules as well as Drupal core ● Breakfast chef. French toast? Pancakes? I’m your man Skills ● Drupal ● Security ● DevOps ● Project Leadership ● Drupal best- practices
  • 6.
    Mark Shropshire Senior Directorof Development /in/markshropshire @shrop ● From Concord, North Carolina ● 20+ years of experience as a technical team leader ● Loves empowering teams to excel while using best of class open source technology solutions. ● Passionate about personal and team growth through mentorship, aligning individual purpose with Mediacurrent’s vision ● Plays sax, drums, keys, and bass and has a list of other instruments that he would love to learn! Skills ● Drupal ● Security ● DevOps ● Flutter ● Acquia Site Factory ● Leadership
  • 7.
    1. What’s Security-First? 2.Security and The Drupal Community 3. OWASP Top 10 Web Vulnerabilities 4. Drupal Best Practices 5. Q&A Today’s Agenda
  • 8.
  • 9.
    Security-First means goingbeyond compliance to assess risk. It’s both a cultural mindset and a continuous development approach that’s rooted in process automation.
  • 10.
    Security-First Planning ● Proactive andcollaborative approach with stakeholders ● Layered defense ● Architecture reviews ● Code reviews ● Automated testing ● Continuous improvements ● Security audits (one-offs and ongoing) ● Documentation
  • 11.
  • 12.
    Drupal Security Team ●Resolves reported security issues in Security Advisories ● Provides assistance for contributed module maintainers in resolving security issues ● Provides documentation on how to write secure code ● Provides documentation on securing your site ● Help the infrastructure team to keep the drupal.org secure ● https://www.drupal.org/security-team
  • 13.
    Guardr is aDrupal distribution with a combination of modules and settings to enhance a Drupal application's security and availability to meet enterprise security requirements. Guardr incorporates industry best practices from security standards, regulatory controls, and security certifications. https://drupal.org/project/guardr Drupal Slack: #contrib-guardr
  • 14.
    OWASP Top 10Web Vulnerabilities
  • 15.
    | 15 Top 10Web Application Security Risks Injection Broken Authentication Sensitive Data Exposure XML External Entities (XXE) Broken Access Control Security Misconfiguration Cross-Site Scripting XSS Insecure Deserialization Using Components with Known Vulnerabilities Insufficient Logging & Monitoring https://owasp.org/www-project-top-ten
  • 16.
  • 17.
    Module Selection ● Module Usage ●Issue Queue Activity ● Security ● Manual Review and Testing ● Release Status ● Commit Activity ● Project information ● Risk Assessment ● Benefit A Guide to Drupal Module Evaluation
  • 18.
    Module patches ● Sometimes, patchesare necessary ● Always submit patches to Drupal.org ● Submitting patches allows: ○ Automated testing ○ Maintainer review ● Patches create: ○ Revision history ○ An opportunity for community input
  • 19.
    Use Drupal APIs UseDrupal APIs to secure your contrib and custom code. https://api.drupal.org/api/drupal Writing secure code for Drupal
  • 20.
    | 20 // Uh,oh: $my_var = "<script>alert('Attack!')</script>"; Not This: $variables['title'] = "Here's a title: " . $my_var; Instead, this: $variables['title'] = t("Here's a title: @title", ['@title' => $my_var]); Also see Drupal::translation()->formatPlural() t()
  • 21.
    | 21 // Uh,oh: $my_var = "<script>alert('Attack!')</script>"; // Oh, no: $my_other_var = "<div>some unexpected HTML</div>"; Not This: $variables['title'] = '<p>' . $my_var . '</p>'; $variables['body'] = $node->get('body')->value . $my_other_var; Instead, this: $variables['title'] = Xss::filter($my_var); $variables['body'] = $node->get('body')->value . Html::escape($my_other_var); Xss::filter() and Html::escape()
  • 22.
    | 22 Monitor Drupal SecurityAdvisories ● Drupal core ● Drupal contrib projects ● Public service announcements ● Notifications via email and RSS ● Follow @drupalsecurity on Twitter ● Drupal Slack #security-questions ● Read SA documentation https://www.drupal.org/security
  • 23.
    | 23 // Uh,oh: $my_var = ", (SELECT * FROM private_data) as attack"; Not this: Drupal::database()->query('SELECT * FROM node_field_data ' . $my_var); Instead, this: // Better. Drupal::database() ->select('node_field_data', 'd') ->fields('d', []) ->condition('d.nid', $my_var); Drupal:database() // Better yet. Drupal::entityTypeManager()-getStorage('node') ->getQuery() ->condition('nid', $my_var);
  • 24.
    | 24 Not this: publicfunction myControllerBuild($nid) { // ... $node = $this->entityTypeManager() ->getStorage('node')->load($nid); // ... $build['node'] = $node->view(); return $build; } Controllers Instead, this: public function myControllerBuild($nid) { // ... $node = $this->entityTypeManager() ->getStorage('node')->load($nid); // ... if($node->access('view', $this->currentUser)) { $build['node'] = $node->view(); } return $build; }
  • 25.
    | 25 Secure youropen source-based martech stack with this resource for best practices. http://bit.ly/open-source-security Download Now CMO’s Guide to Open Source Security
  • 26.
    | 26 Key Takeaways Cultivatea security-first culture. Educate yourself on security risks that can impact your organization. Review and monitor Drupal security advisories. Follow Drupal best practices. Automate security processes. Promptly update security releases.
  • 27.