SlideShare a Scribd company logo
@adam_englander
Practical API Security
Adam Englander, Software Architect
iovation
@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
Access Control
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging
Access Control
@adam_englander
@adam_englander
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging
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
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
DO NOT USE!
@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
Access Control
@adam_englander
Defense in Depth
Transport Layer Security
Rate Limiting/Replay Prevention
Authentication
Data Validation
Data Encryption
Logging
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
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
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 tools like ELK or Greylog
to aggregate logs
@adam_englander
Determine anomalous conditions
and alert on those conditions.
@adam_englander
And now we code…

More Related Content

PDF
Practical API Security - Midwest PHP 2018
PDF
Cryptography for Beginners - Midwest PHP 2018
PPTX
Authentication for Droids
PDF
API documentation
PDF
Devoxx Ukraine 2018 "Break me if you can: practical guide to building fault-t...
PPTX
Practical API Security - PyCon 2018
PDF
Practical API Security - PyCon 2019
PPTX
API Security - Null meet
Practical API Security - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
Authentication for Droids
API documentation
Devoxx Ukraine 2018 "Break me if you can: practical guide to building fault-t...
Practical API Security - PyCon 2018
Practical API Security - PyCon 2019
API Security - Null meet

Similar to ZendCon 2018 - Practical API Security (20)

PPTX
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
PPTX
How to build Simple yet powerful API.pptx
PDF
Api security-testing
PPTX
Rest API Security - A quick understanding of Rest API Security
PPTX
Unit 3_detailed_automotiving_mobiles.pptx
PPTX
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
PDF
FIWARE ID Management
PDF
Checkmarx meetup API Security - API Security in depth - Inon Shkedy
PDF
API Security - OWASP top 10 for APIs + tips for pentesters
PDF
apidays Hong Kong - Attack API Architecture, Alvin Tam, Hong Kong Computer So...
PPTX
Rest API Security
PDF
Securing Web Applications with Token Authentication
PPTX
PDF
Building a secure BFF at Postman
PPTX
APIs: The New Security Layer
PDF
Protecting Your APIs Against Attack & Hijack
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
PPT
Scalable Reliable Secure REST
PDF
PDF
Black and Blue APIs: Attacker's and Defender's View of API Vulnerabilities
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
How to build Simple yet powerful API.pptx
Api security-testing
Rest API Security - A quick understanding of Rest API Security
Unit 3_detailed_automotiving_mobiles.pptx
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
FIWARE ID Management
Checkmarx meetup API Security - API Security in depth - Inon Shkedy
API Security - OWASP top 10 for APIs + tips for pentesters
apidays Hong Kong - Attack API Architecture, Alvin Tam, Hong Kong Computer So...
Rest API Security
Securing Web Applications with Token Authentication
Building a secure BFF at Postman
APIs: The New Security Layer
Protecting Your APIs Against Attack & Hijack
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Scalable Reliable Secure REST
Black and Blue APIs: Attacker's and Defender's View of API Vulnerabilities
Ad

More from Adam Englander (20)

PPTX
Making PHP Smarter - Dutch PHP 2023.pptx
PDF
Threat Modeling for Dummies
PDF
ZendCon 2018 - Cryptography in Depth
PDF
Threat Modeling for Dummies - Cascadia PHP 2018
PDF
Dutch PHP 2018 - Cryptography for Beginners
PDF
php[tek] 2108 - Cryptography Advances in PHP 7.2
PDF
php[tek] 2018 - Biometrics, fantastic failure point of the future
PDF
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
PDF
Cryptography for Beginners - Sunshine PHP 2018
PDF
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
PDF
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
PDF
ZendCon 2017 - Cryptography for Beginners
PDF
ZendCon 2017: The Red Team is Coming
PDF
ZendCon 2017 - Build a Bot Workshop - Async Primer
PDF
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
PDF
Coder Cruise 2017 - The Red Team Is Coming
PDF
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
PDF
Build a bot workshop async primer - php[tek]
PDF
Python and Docker
PDF
Concurrent Programming in Python
Making PHP Smarter - Dutch PHP 2023.pptx
Threat Modeling for Dummies
ZendCon 2018 - Cryptography in Depth
Threat Modeling for Dummies - Cascadia PHP 2018
Dutch PHP 2018 - Cryptography for Beginners
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2018 - Biometrics, fantastic failure point of the future
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Cryptography for Beginners - Sunshine PHP 2018
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017: The Red Team is Coming
ZendCon 2017 - Build a Bot Workshop - Async Primer
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Coder Cruise 2017 - The Red Team Is Coming
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Build a bot workshop async primer - php[tek]
Python and Docker
Concurrent Programming in Python
Ad

Recently uploaded (20)

PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
August Patch Tuesday
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Getting Started with Data Integration: FME Form 101
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
Teaching material agriculture food technology
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Mushroom cultivation and it's methods.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Group 1 Presentation -Planning and Decision Making .pptx
Encapsulation_ Review paper, used for researhc scholars
Heart disease approach using modified random forest and particle swarm optimi...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
August Patch Tuesday
Mobile App Security Testing_ A Comprehensive Guide.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Getting Started with Data Integration: FME Form 101
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Unlocking AI with Model Context Protocol (MCP)
Programs and apps: productivity, graphics, security and other tools
Teaching material agriculture food technology
Univ-Connecticut-ChatGPT-Presentaion.pdf
Mushroom cultivation and it's methods.pdf

ZendCon 2018 - Practical API Security