SAFER Odoo Code
Olivier Dony
Platform & Security
security@odoo.com - @odony
2017
EXPERIENCE
and the pursuit thereof...
GOALS.
1. Word about our security team
2. Framework security features
3. Evolutions
4. Recap of common mistakes
GOAL.
A word about the Odoo security team
MISSIONS
Single point of contact - security@odoo.com
Priority answer (~24h)
Disclosure process & policy
odoo.com/security-report
Questions, audit reviews, bugs,...
Internal reviews (transversal)
Raising awareness
Security Advisories (CVEs)
Launch
Year after year...
150+ TICKETS
Self-XSS
FALSEPOSITIVE
DKIM/DMARC
Policy
SSL modulus
Version discl.
Unexploitable
XSS
XSS
Broken
authentication
Code Exec.
REALTHREAT
Phishing
Path discl.
Audit
review
This year...
The visible parts of
the iceberg
Our heroes...
GOAL.
Framework security features
THE SECURITY
MODEL Business
Data
DATA
ACCESS
LAYER
ACCESS CONTROL
Groups
ACL
Rules
ODOO
APPS
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
Built-in sessions
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
Built-in sessions
High-level templ. language
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
Built-in sessions
High-level templ. language
CRUD-level access control
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
Built-in sessions
High-level templ. language
CRUD-level access control
CRUD-level access control
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
Built-in sessions
High-level templ. language
CRUD-level access control
CRUD-level access control
CSRF protection for forms
OWASP Top 10
The Odoo framework is
designed to help developers
avoid those common pitfalls
OWASP Top 10 (2013)
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery
A9 - Using Known Vulnerable Components
A10 - Unvalidated Redirects and Forwards
High level query primitives
Built-in sessions
High-level templ. language
CRUD-level access control
CRUD-level access control
CSRF protection for forms
Reduced sets of deps.
GOAL.
Highlight framework security-related evolutions
Extra security logs
HTTP-only session
cookies
Encrypted master
password*
*hashed, of course (PBKDF2-SHA512)
Database manager can be deactivated
RPC calls blocked too!
--no-database-list
will now block access to
database management
screens
Encrypted database connections (tcp)
SSL mode Eavesdrop MITM
disable / /
allow ? /
prefer ? /
require OK /
verify-ca OK ~OK
verify-full OK OK
No more Pickle!
Welcome JSON!
Restricted system parameters
Admin-only
access!
Hardened access rights on internal data
Odoo 10 Odoo 11
GOAL.
Recap of common coding mistakes
GOAL.MISTAKE #1: using eval to parse text
It breaks the barrier between code and data
GOAL.MISTAKE #1: using eval to parse text
There are smarter and safer ways to parse literals
Language Data type Suitable parser
Python int, float, etc. int(), float()
Javascript int, float, etc. parseInt(), parseFloat()
Python dict json.loads(), ast.literal_eval()
Javascript object JSON.parse()
... ... ...
GOAL.MISTAKE #1: using eval to parse text
And when you must
eval(), be doubly careful
Custom piece
of logic
Parametrized
rendering
User-
provided
data
Worried developer
GOAL.MISTAKE #2: handcrafted SQL
It’s easy to get it wrong
GOAL.MISTAKE #2: handcrafted SQL
It’s easy to get it wrong
Nope, you
can’t do that
GOAL.MISTAKE #2: handcrafted SQL
It’s easy to get it wrong
Separate
code vs
parameters
GOAL.MISTAKE #3: XSS vectors
t-esc=”task.name“ t-raw=”task.name“ t-raw=”sanitized_body“
YES! ☺ NO! 😠 MAYBE… ☹
t-field=”task.name“
<span t-field=”task.name”
t-attf-class=”o_task_{{task.state}}“
/>
task_cls = ‘o_task_%s‘ % 
task.state
task = ‘<span class=”%s”/>%s’ % (
task_cls, task.name
)
...
<span t-raw=”task“/>
task_cls = ‘o_task_%s‘ % 
escape(task.state)
task = ‘<span class=”%s”/>%s’ % (
task_cls, escape(task.name)
)
...
<span t-raw=”task“/>
MISTAKE #4: careless sudo usage
Keep the sudo scope as limited
as possible
Review 2x all calls done as
super-user, watch out for leaked
objects and side-effects
And there's more...
Other examples and explanations
in "Top 10 rules" talk from Odoo
Experience 2016.
https://www.odoo.com/r/h3s
TAKEAWAYS.
The framework tries to protect you from harm...
as long as you don’t bypass the protections!
And it's improving year after year…
Get in touch with us whenever you have security
questions… security@odoo.com
SAFER Odoo Code
Olivier Dony
Platform & Security
security@odoo.com
2017
EXPERIENCE
and the pursuit thereof...
Photos credits:
https://www.flickr.com/photos/steve_rider/
https://www.flickr.com/photos/ericprunier/
https://www.flickr.com/photos/jezbags/
https://www.flickr.com/photos/150472095@N05/
https://www.flickr.com/photos/loosetrucks/

Safer Odoo Code [Odoo Experience 2017]

  • 1.
    SAFER Odoo Code OlivierDony Platform & Security security@odoo.com - @odony 2017 EXPERIENCE and the pursuit thereof...
  • 2.
    GOALS. 1. Word aboutour security team 2. Framework security features 3. Evolutions 4. Recap of common mistakes
  • 3.
    GOAL. A word aboutthe Odoo security team
  • 4.
    MISSIONS Single point ofcontact - security@odoo.com Priority answer (~24h) Disclosure process & policy odoo.com/security-report Questions, audit reviews, bugs,... Internal reviews (transversal) Raising awareness Security Advisories (CVEs)
  • 5.
  • 6.
    150+ TICKETS Self-XSS FALSEPOSITIVE DKIM/DMARC Policy SSL modulus Versiondiscl. Unexploitable XSS XSS Broken authentication Code Exec. REALTHREAT Phishing Path discl. Audit review This year...
  • 7.
    The visible partsof the iceberg
  • 8.
  • 9.
  • 10.
  • 11.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards
  • 12.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards
  • 13.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives
  • 14.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives Built-in sessions
  • 15.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives Built-in sessions High-level templ. language
  • 16.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives Built-in sessions High-level templ. language CRUD-level access control
  • 17.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives Built-in sessions High-level templ. language CRUD-level access control CRUD-level access control
  • 18.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives Built-in sessions High-level templ. language CRUD-level access control CRUD-level access control CSRF protection for forms
  • 19.
    OWASP Top 10 TheOdoo framework is designed to help developers avoid those common pitfalls OWASP Top 10 (2013) A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery A9 - Using Known Vulnerable Components A10 - Unvalidated Redirects and Forwards High level query primitives Built-in sessions High-level templ. language CRUD-level access control CRUD-level access control CSRF protection for forms Reduced sets of deps.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
    Database manager canbe deactivated RPC calls blocked too! --no-database-list will now block access to database management screens
  • 25.
    Encrypted database connections(tcp) SSL mode Eavesdrop MITM disable / / allow ? / prefer ? / require OK / verify-ca OK ~OK verify-full OK OK
  • 26.
  • 27.
  • 28.
    Hardened access rightson internal data Odoo 10 Odoo 11
  • 29.
    GOAL. Recap of commoncoding mistakes
  • 30.
    GOAL.MISTAKE #1: usingeval to parse text It breaks the barrier between code and data
  • 31.
    GOAL.MISTAKE #1: usingeval to parse text There are smarter and safer ways to parse literals Language Data type Suitable parser Python int, float, etc. int(), float() Javascript int, float, etc. parseInt(), parseFloat() Python dict json.loads(), ast.literal_eval() Javascript object JSON.parse() ... ... ...
  • 32.
    GOAL.MISTAKE #1: usingeval to parse text And when you must eval(), be doubly careful Custom piece of logic Parametrized rendering User- provided data Worried developer
  • 33.
    GOAL.MISTAKE #2: handcraftedSQL It’s easy to get it wrong
  • 34.
    GOAL.MISTAKE #2: handcraftedSQL It’s easy to get it wrong Nope, you can’t do that
  • 35.
    GOAL.MISTAKE #2: handcraftedSQL It’s easy to get it wrong Separate code vs parameters
  • 36.
    GOAL.MISTAKE #3: XSSvectors t-esc=”task.name“ t-raw=”task.name“ t-raw=”sanitized_body“ YES! ☺ NO! 😠 MAYBE… ☹ t-field=”task.name“ <span t-field=”task.name” t-attf-class=”o_task_{{task.state}}“ /> task_cls = ‘o_task_%s‘ % task.state task = ‘<span class=”%s”/>%s’ % ( task_cls, task.name ) ... <span t-raw=”task“/> task_cls = ‘o_task_%s‘ % escape(task.state) task = ‘<span class=”%s”/>%s’ % ( task_cls, escape(task.name) ) ... <span t-raw=”task“/>
  • 37.
    MISTAKE #4: carelesssudo usage Keep the sudo scope as limited as possible Review 2x all calls done as super-user, watch out for leaked objects and side-effects
  • 38.
    And there's more... Otherexamples and explanations in "Top 10 rules" talk from Odoo Experience 2016. https://www.odoo.com/r/h3s
  • 39.
    TAKEAWAYS. The framework triesto protect you from harm... as long as you don’t bypass the protections! And it's improving year after year… Get in touch with us whenever you have security questions… security@odoo.com
  • 40.
    SAFER Odoo Code OlivierDony Platform & Security security@odoo.com 2017 EXPERIENCE and the pursuit thereof... Photos credits: https://www.flickr.com/photos/steve_rider/ https://www.flickr.com/photos/ericprunier/ https://www.flickr.com/photos/jezbags/ https://www.flickr.com/photos/150472095@N05/ https://www.flickr.com/photos/loosetrucks/