SlideShare a Scribd company logo
@adam_englander
Practical API Security
Adam Englander, Engineering Manager
iovation
@adam_englander
And now, the morning
announcements…
@adam_englander
Break will be at 10:15 in the
lobby
@adam_englander
Lunch will be from 12:20 - 1:20
In the Gerard Ballroom AB
@adam_englander
There is as much as PyCon
could afford
Please share power
@adam_englander
Please rate this…
https://www.surveymonkey.com/r/YHSX9MC
@adam_englander
Let's set some expectations...
@adam_englander
What are we protecting against?
@adam_englander
@adam_englander
How do we provide that
protection?
@adam_englander
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
@adam_englander
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Replay prevention requires
unique requests
@adam_englander
Determine Uniqueness of Request
GET / HTTP/1.1
Accept: application/json
@adam_englander
Determine Uniqueness of Request
GET / HTTP/1.1
Accept: application/json
X-Nonce: 5ed518e8c5c51a64638b2b50c192242d
@adam_englander
Store that unique value in a
datastore so you can verify you
don't see it again
@adam_englander
Use the add function on the
cache to prevent race conditions
@adam_englander
Cache Example
if ($token === null) {
throw new AuthorizationRequiredException();
} elseif (!$this->cache->add(hash('sha512', $token), 1, 10)) {
throw new InvalidRequestException();
}
@adam_englander
Use insert on unique index for
RDBMS to prevent race
conditions
@adam_englander
Rate limiting requires unique
identification for restrictions
@adam_englander
api-user-id|create-widget|20:01
ebf4e1d4bb33e5f6028e8443d6a1d6aa
@adam_englander
Use the add and increment
functions of the cache to
prevent race conditions
@adam_englander
Cache Example
$key = sprintf("%s|root-post|%s", $userId, $timeSlice);
$this->cache->add($key, 0, 1);
$total = $this->cache->increment($key);
@adam_englander
Use insert with unique index
and update returning in RDBMS
to prevent race conditions
@adam_englander
Data stores can be done in
three ways.
@adam_englander
In Memory Datastore
@adam_englander
Local Datastore
@adam_englander
Global Datastore
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Do not make authentication part
of the body
@adam_englander
Use the Authorization header
@adam_englander
HTTP Basic Authentication
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
@adam_englander
HTTP Digest Authentication
Authorization: Digest username="Awesome",
realm=“example@10x.wtf",
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
uri=“/",
qop=auth,
nc=00000001,
cnonce="0a4f113b",
response="6629fae49393a05397450978507c4ef1",
opaque="5ccc069c403ebaf9f0171e9517f40e41"
@adam_englander
HTTP Bearer Authentication
Authorization: Bearer mF_9.B5f-4.1JqM
@adam_englander
Roll Your Own
@adam_englander
Many APIs do this
@adam_englander
What about never rolling your
own crypto?
@adam_englander
Single Use JWT
@adam_englander
No auth service required
@adam_englander
Can use existing JWT libraries
to create and validate
@adam_englander
Can be extended beyond auth
to provide data validation and
MITM protection
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Message Validation
@adam_englander
Request Validation
@adam_englander
Method Validation
GET /user/abc HTTP/1.1
Accept: application/json
@adam_englander
Method Validation
DELETE /user/abc HTTP/1.1
Accept: application/json
@adam_englander
Path Validation
GET /user/abc HTTP/1.1
Accept: application/json
@adam_englander
Path Validation
GET /user/def HTTP/1.1
Accept: application/json
@adam_englander
Body Validation
PATCH /user/abc HTTP/1.1
{"email": "valid@user.com"}
@adam_englander
Body Validation
PATCH /user/abc HTTP/1.1
{"email": "pwned@hkr.com"}
@adam_englander
Response Validation
@adam_englander
Status Code Validation
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21
{"expected": "value"}
@adam_englander
Status Code Validation
HTTP/1.1 400 Invalid Request
Content-Type: application/json; charset=UTF-8
Content-Length: 21
{"expected": "value"}
@adam_englander
Status Code Validation
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21
{"expected": "value"}
@adam_englander
Status Code Validation
HTTP/1.1 301 Moved
Content-Type: application/json; charset=UTF-8
Content-Length: 21
Location: https://bad.actor.com
{"expected": "value"}
@adam_englander
Header Validation
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21
Cache-Control: no-cache
{"expected": "value"}
@adam_englander
Header Validation
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21
Cache-Control: max-age=99999999
{"expected": "value"}
@adam_englander
Data Validation
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21
{"active": false}
@adam_englander
Data Validation
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 21
{"active": true}
@adam_englander
Validation of request data
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Encrypt Data at Rest
@adam_englander
Use a structure format that
allows for in-place key rotation
and nonce storage
@adam_englander
COSE
CBOR Object Signing and Encryption (COSE)
Concise Binary Object Representation (CBOR)
@adam_englander
Roll Your Own
keyid|nonce|encrypted-data
@adam_englander
Encrypt Data in Transit
@adam_englander
WW?D
@adam_englander
JSON Web Encryption
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging/Tracing
Access Control
@adam_englander
Log Everything
@adam_englander
Log in a structured format for
easier parsing
@adam_englander
Log all pertinent actions
@adam_englander
Include all data regarding state.
Anonymize sensitive data.
@adam_englander
Include origin data to identify
bad actors.
@adam_englander
Utilize OpenTracing tools to
track all the pertinent things
@adam_englander
Utilize tools like ELK or Greylog
to aggregate logs
@adam_englander
Determine anomalous conditions
and alert on those conditions.
@adam_englander
And now we code…
@adam_englander
Please rate this…
https://www.surveymonkey.com/r/YHSX9MC

More Related Content

What's hot (10)

ODP
BSides Columbus: Active Defense - Helping threat actors hack themselves!
ThreatReel Podcast
 
PDF
Finding Bugs FASTER with Fuzzing
Alper Başaran
 
PDF
Understanding Information Security Assessment Types
HackerOne
 
PDF
Why Web Security Matters!
Philippe De Ryck
 
PDF
Demystifying observability
Abigail Bangser
 
PPTX
Talk @FH Hagenberg - Data viz in a collaborative mixed reality space
Stefan Wasserbauer
 
PPTX
Black ops 2012
Dan Kaminsky
 
PPTX
How to Protect Yourself From Heartbleed Security Flaw
ConnectSafely
 
PPTX
Deep learning for mere mortals - Devoxx Belgium 2015
Samir Bessalah
 
PDF
Cred stealing emails bsides austin_2018 v1.0
Michael Gough
 
BSides Columbus: Active Defense - Helping threat actors hack themselves!
ThreatReel Podcast
 
Finding Bugs FASTER with Fuzzing
Alper Başaran
 
Understanding Information Security Assessment Types
HackerOne
 
Why Web Security Matters!
Philippe De Ryck
 
Demystifying observability
Abigail Bangser
 
Talk @FH Hagenberg - Data viz in a collaborative mixed reality space
Stefan Wasserbauer
 
Black ops 2012
Dan Kaminsky
 
How to Protect Yourself From Heartbleed Security Flaw
ConnectSafely
 
Deep learning for mere mortals - Devoxx Belgium 2015
Samir Bessalah
 
Cred stealing emails bsides austin_2018 v1.0
Michael Gough
 

Similar to Practical API Security - PyCon 2019 (20)

PPTX
Practical API Security - PyCon 2018
Adam Englander
 
PDF
ZendCon 2018 - Practical API Security
Adam Englander
 
PDF
Practical API Security - Midwest PHP 2018
Adam Englander
 
PDF
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Adam Englander
 
PDF
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Adam Englander
 
PDF
Saml authentication bypass
Tarachand Verma
 
PDF
Securing Web Applications with Token Authentication
Stormpath
 
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
PPTX
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
CODE BLUE
 
PPTX
Codemash-2017
Kevin Cody
 
PDF
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
Adam Englander
 
PPTX
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
PDF
JDD2015: Security in the era of modern applications and services - Bolesław D...
PROIDEA
 
PDF
APIsecure 2023 - OAuth, OIDC and protecting third-party credentials, Ed Olson...
apidays
 
PDF
Are You Properly Using JWTs?
42Crunch
 
PDF
Centralise legacy auth at the ingress gateway
Andrew Kirkpatrick
 
PDF
API Security - OWASP top 10 for APIs + tips for pentesters
Inon Shkedy
 
PPTX
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
PDF
Checkmarx meetup API Security - API Security in depth - Inon Shkedy
Adar Weidman
 
PPTX
The Client is not always right! How to secure OAuth authentication from your...
Mike Schwartz
 
Practical API Security - PyCon 2018
Adam Englander
 
ZendCon 2018 - Practical API Security
Adam Englander
 
Practical API Security - Midwest PHP 2018
Adam Englander
 
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Adam Englander
 
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Adam Englander
 
Saml authentication bypass
Tarachand Verma
 
Securing Web Applications with Token Authentication
Stormpath
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
CODE BLUE
 
Codemash-2017
Kevin Cody
 
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
Adam Englander
 
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
JDD2015: Security in the era of modern applications and services - Bolesław D...
PROIDEA
 
APIsecure 2023 - OAuth, OIDC and protecting third-party credentials, Ed Olson...
apidays
 
Are You Properly Using JWTs?
42Crunch
 
Centralise legacy auth at the ingress gateway
Andrew Kirkpatrick
 
API Security - OWASP top 10 for APIs + tips for pentesters
Inon Shkedy
 
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
Checkmarx meetup API Security - API Security in depth - Inon Shkedy
Adar Weidman
 
The Client is not always right! How to secure OAuth authentication from your...
Mike Schwartz
 
Ad

More from Adam Englander (20)

PPTX
Making PHP Smarter - Dutch PHP 2023.pptx
Adam Englander
 
PDF
ZendCon 2018 - Cryptography in Depth
Adam Englander
 
PDF
Dutch PHP 2018 - Cryptography for Beginners
Adam Englander
 
PDF
php[tek] 2108 - Cryptography Advances in PHP 7.2
Adam Englander
 
PDF
php[tek] 2018 - Biometrics, fantastic failure point of the future
Adam Englander
 
PDF
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Adam Englander
 
PDF
Cryptography for Beginners - Midwest PHP 2018
Adam Englander
 
PDF
Cryptography for Beginners - Sunshine PHP 2018
Adam Englander
 
PDF
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
Adam Englander
 
PDF
ZendCon 2017 - Cryptography for Beginners
Adam Englander
 
PDF
ZendCon 2017: The Red Team is Coming
Adam Englander
 
PDF
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
PDF
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Adam Englander
 
PDF
Coder Cruise 2017 - The Red Team Is Coming
Adam Englander
 
PDF
Build a bot workshop async primer - php[tek]
Adam Englander
 
PDF
Python and Docker
Adam Englander
 
PDF
Concurrent Programming in Python
Adam Englander
 
PDF
Biometrics - Fantastic Failure Point of the Future
Adam Englander
 
PDF
IoT Lock Down - Battling the Bot Net Builders
Adam Englander
 
PDF
SunshinePHP 2017: Tales From The Crypt - A Cryptography Primer
Adam Englander
 
Making PHP Smarter - Dutch PHP 2023.pptx
Adam Englander
 
ZendCon 2018 - Cryptography in Depth
Adam Englander
 
Dutch PHP 2018 - Cryptography for Beginners
Adam Englander
 
php[tek] 2108 - Cryptography Advances in PHP 7.2
Adam Englander
 
php[tek] 2018 - Biometrics, fantastic failure point of the future
Adam Englander
 
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Adam Englander
 
Cryptography for Beginners - Midwest PHP 2018
Adam Englander
 
Cryptography for Beginners - Sunshine PHP 2018
Adam Englander
 
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
Adam Englander
 
ZendCon 2017 - Cryptography for Beginners
Adam Englander
 
ZendCon 2017: The Red Team is Coming
Adam Englander
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander
 
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Adam Englander
 
Coder Cruise 2017 - The Red Team Is Coming
Adam Englander
 
Build a bot workshop async primer - php[tek]
Adam Englander
 
Python and Docker
Adam Englander
 
Concurrent Programming in Python
Adam Englander
 
Biometrics - Fantastic Failure Point of the Future
Adam Englander
 
IoT Lock Down - Battling the Bot Net Builders
Adam Englander
 
SunshinePHP 2017: Tales From The Crypt - A Cryptography Primer
Adam Englander
 
Ad

Recently uploaded (20)

PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 

Practical API Security - PyCon 2019