SlideShare a Scribd company logo
Complete Guide to Setup
Secure Scheme for Restful
APIs
By Derric Gilling (Derric@moesif.com)
CEO, Moesif.com
Outline
• Steps For Setup a Security Scheme For Your Restful
APIs.
• Define the objectives for your API security
• How to pick the right token scheme
• How to send the token
• How to store the token
Objective 1 - Authentication
• Involves verifying who the person says he/she is.
This may involve checking a username/password or
checking that a token is signed and not expired.
Authentication does not say this person can access
a particular resources.
Objective 2 - Authorization
• Involves checking resources that the user is
authorized to access or modify via defined roles or
claims. For example, the authenticated user is
authorized for read access to a database but not
allowed to modify it. The same can be applied to
your API. Maybe most users can access certain
resources or endpoints, but special admin users
have privileged access.
Options for Tokens
• For Restful APIs, the security is usually token based:
• JWT Tokens
• Opaque Tokens
• A blend
What is JWT Token
• JWT Tokens: a full JSON Object that has been
base64 encoded and then signed with either a
symmetric shared key or using a public/private
key pair
Content & Generation of JWT
Token:
• The JWT can commonly contain
• subject or user_id
• when the token was issued
• Permissions/Roles for this user
• Expiration date
• By signing with a secret, you ensure that only you
can generate a token and thus was not tampered
with.
• Any web service can verify the token is from you by
using your public key.
Important Notes Regarding JWT
Token
• JWTs are usually not encrypted (signed is different
than encrypted).
• It is good practice to place identifiers in the token
such as a user_id, but not personally identifiable
information like an email or social security number
Advantages of JWT Tokens
• No need for centralized authentication servers and
databases.
• All the information required to authenticate the user is
contained within the token itself.
• Verifying that a token is correctly signed only takes
CPU Cycles and requires no IO or network access
and very easy to scale on modern web server
hardware.
• Verifying consists of checking signature and a few
parameters such as the claims and when the token
expires.
Disadvantage of JWT Tokens
• Banning or removing Roles Immediately is harder.
• Token usually is valid until its expiration date.
• Token is stored on the client side (by the user).
• Mitigations:
• Store blacklisted JTI claims (Token Id) in a Db.
• Token can grow in size as more fields are added.
• Since Token needs to be sent on every request for
stateless APIs, it can add to data usage for mobile users.
What are Opaque Tokens?
• Instead of storing user identity and claims in the
token, the opaque token is simply a primary key
that references a database entry which has the
data.
• Fast key value stores like Redis are important for
leveraging in memory hash tables for O(1) lookup
of the payload.
Advantages of Opaque Tokens:
• Since the roles are read from a database directly,
roles can be changed and the user will see the new
roles as soon as the changes propagate through
your backend.
Disadvantages of Opaque Tokens:
• Added complexity of maintaining the K/V store and
the auth server.
• Each service may have to handshake with the auth
server to get the claims or roles.
A Blended Strategy
• Handle authentication via JWT such as checking
that the user is who they say they are.
• JWT only handles the authentication side but not
authorization side.
How to Send Tokens
• Avoid URL Query Params:
• Because users often copy past and share URLs.
• Loggers often record URLs in plain text.
• Headers:
• ‘Authorization’ Header: Most popular method.
• Cookies:
• Essentially, when cookie sent to the server, it is just
another header.
How to Store Tokens on Client
Side? Option 1: Cookies
• Pros:
• Immune to XSS attacks
• If set flags to enforce security checks such as HTTP only and
Secure. The cookie can’t be read by Javascript.
• Cons:
• Vulnerable to cross site request forgery (XSRF or CSRF).
• Sent for every request, static, AJAX, etc.
• Mitigation Strategy: server needs to recognize whether
the request came from your real website running in a
browser or someone else.
• Hidden anti-forgery token
• Generate and store a special random key in the cookie
How to Store Tokens on Client
Side? Option 2: Local Storage
• Pros:
• Immune to XSRF Attacks.
• Cons:
• Subject to Cross-Scripting attacks (XSS)
• Local Storage is global to your website domain. Thus, any
Javascript on your website, 3rd party lib or not, can access the
same local storage.
• Mitigation:
• Ensure the scripts you import into your website are safe.
• Can’t access it across multiple subdomains.
Questions / Comments?
Email: derric@moesif.com

More Related Content

What's hot (20)

PPT
SSO_Good_Bad_Ugly
Steve Markey
 
PDF
JDD2015: Security in the era of modern applications and services - Bolesław D...
PROIDEA
 
PPTX
Authentication vs authorization
Frank Victory
 
PDF
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
Sam Bowne
 
PDF
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Sam Bowne
 
PDF
CNIT 129S: Ch 6: Attacking Authentication
Sam Bowne
 
PDF
Building a secure BFF at Postman
Ankit Muchhala
 
PDF
CNIT 129S: Ch 4: Mapping the Application
Sam Bowne
 
PPT
Single sign on assistant an authentication brokers
Finalyear Projects
 
PDF
OpenID Connect vs. OpenID 1 & 2
Mike Schwartz
 
PDF
referer spoof
blackprice2
 
PPTX
SSO introduction
Aidy Tificate
 
PDF
Understanding Claim based Authentication
Mohammad Yousri
 
PDF
CNIT 129S: 8: Attacking Access Controls
Sam Bowne
 
PPTX
OpenID Connect: An Overview
Pat Patterson
 
PDF
Design and Implementation of an IP based authentication mechanism for Open So...
WilliamJohn41
 
PDF
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
Sam Bowne
 
PDF
CNIT 129S: 11: Attacking Application Logic
Sam Bowne
 
PDF
CIS14: Consolidating Authorization for API and Web SSO using OpenID Connect
CloudIDSummit
 
PDF
Mobile security chess board - attacks & defense
Blueinfy Solutions
 
SSO_Good_Bad_Ugly
Steve Markey
 
JDD2015: Security in the era of modern applications and services - Bolesław D...
PROIDEA
 
Authentication vs authorization
Frank Victory
 
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
Sam Bowne
 
Ch 1: Web Application (In)security & Ch 2: Core Defense Mechanisms
Sam Bowne
 
CNIT 129S: Ch 6: Attacking Authentication
Sam Bowne
 
Building a secure BFF at Postman
Ankit Muchhala
 
CNIT 129S: Ch 4: Mapping the Application
Sam Bowne
 
Single sign on assistant an authentication brokers
Finalyear Projects
 
OpenID Connect vs. OpenID 1 & 2
Mike Schwartz
 
referer spoof
blackprice2
 
SSO introduction
Aidy Tificate
 
Understanding Claim based Authentication
Mohammad Yousri
 
CNIT 129S: 8: Attacking Access Controls
Sam Bowne
 
OpenID Connect: An Overview
Pat Patterson
 
Design and Implementation of an IP based authentication mechanism for Open So...
WilliamJohn41
 
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
Sam Bowne
 
CNIT 129S: 11: Attacking Application Logic
Sam Bowne
 
CIS14: Consolidating Authorization for API and Web SSO using OpenID Connect
CloudIDSummit
 
Mobile security chess board - attacks & defense
Blueinfy Solutions
 

Similar to Complete Guide to Setup Secure Scheme for Restful APIs (20)

PPT
Securing RESTful API
Muhammad Zbeedat
 
PPTX
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
PDF
Securing Web Applications with Token Authentication
Stormpath
 
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
PDF
API SECURITY
Tubagus Rizky Dharmawan
 
PDF
Oauth Nightmares Abstract OAuth Nightmares
Nino Ho
 
PPTX
Pentesting jwt
Jaya Kumar Kondapalli
 
PPTX
REST API Security: OAuth 2.0, JWTs, and More!
Stormpath
 
PDF
When and Why Would I use Oauth2?
Dave Syer
 
PPTX
JWT Authentication with AngularJS
robertjd
 
PPTX
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
PPTX
IEEE WEB DOCUMENT PPT FOR EXPLANATION OF THE TOPIC
sujalmacbookm2air
 
PDF
OAuth and why you should use it
Sergey Podgornyy
 
PDF
Apidays Paris 2023 - I Have an OAuth2 Access Token, Now what do I do with it,...
apidays
 
PDF
Are You Properly Using JWTs?
42Crunch
 
PPTX
Building Secure User Interfaces With JWTs
robertjd
 
PDF
Json web token api authorization
Giulio De Donato
 
PPTX
Restful api
Anurag Srivastava
 
PPTX
Microservices Manchester: Authentication in Microservice Systems by David Borsos
OpenCredo
 
PDF
REST API Authentication Methods.pdf
Rubersy Ramos García
 
Securing RESTful API
Muhammad Zbeedat
 
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
Securing Web Applications with Token Authentication
Stormpath
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
Oauth Nightmares Abstract OAuth Nightmares
Nino Ho
 
Pentesting jwt
Jaya Kumar Kondapalli
 
REST API Security: OAuth 2.0, JWTs, and More!
Stormpath
 
When and Why Would I use Oauth2?
Dave Syer
 
JWT Authentication with AngularJS
robertjd
 
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
IEEE WEB DOCUMENT PPT FOR EXPLANATION OF THE TOPIC
sujalmacbookm2air
 
OAuth and why you should use it
Sergey Podgornyy
 
Apidays Paris 2023 - I Have an OAuth2 Access Token, Now what do I do with it,...
apidays
 
Are You Properly Using JWTs?
42Crunch
 
Building Secure User Interfaces With JWTs
robertjd
 
Json web token api authorization
Giulio De Donato
 
Restful api
Anurag Srivastava
 
Microservices Manchester: Authentication in Microservice Systems by David Borsos
OpenCredo
 
REST API Authentication Methods.pdf
Rubersy Ramos García
 
Ad

Recently uploaded (20)

PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Ad

Complete Guide to Setup Secure Scheme for Restful APIs

  • 1. Complete Guide to Setup Secure Scheme for Restful APIs By Derric Gilling ([email protected]) CEO, Moesif.com
  • 2. Outline • Steps For Setup a Security Scheme For Your Restful APIs. • Define the objectives for your API security • How to pick the right token scheme • How to send the token • How to store the token
  • 3. Objective 1 - Authentication • Involves verifying who the person says he/she is. This may involve checking a username/password or checking that a token is signed and not expired. Authentication does not say this person can access a particular resources.
  • 4. Objective 2 - Authorization • Involves checking resources that the user is authorized to access or modify via defined roles or claims. For example, the authenticated user is authorized for read access to a database but not allowed to modify it. The same can be applied to your API. Maybe most users can access certain resources or endpoints, but special admin users have privileged access.
  • 5. Options for Tokens • For Restful APIs, the security is usually token based: • JWT Tokens • Opaque Tokens • A blend
  • 6. What is JWT Token • JWT Tokens: a full JSON Object that has been base64 encoded and then signed with either a symmetric shared key or using a public/private key pair
  • 7. Content & Generation of JWT Token: • The JWT can commonly contain • subject or user_id • when the token was issued • Permissions/Roles for this user • Expiration date • By signing with a secret, you ensure that only you can generate a token and thus was not tampered with. • Any web service can verify the token is from you by using your public key.
  • 8. Important Notes Regarding JWT Token • JWTs are usually not encrypted (signed is different than encrypted). • It is good practice to place identifiers in the token such as a user_id, but not personally identifiable information like an email or social security number
  • 9. Advantages of JWT Tokens • No need for centralized authentication servers and databases. • All the information required to authenticate the user is contained within the token itself. • Verifying that a token is correctly signed only takes CPU Cycles and requires no IO or network access and very easy to scale on modern web server hardware. • Verifying consists of checking signature and a few parameters such as the claims and when the token expires.
  • 10. Disadvantage of JWT Tokens • Banning or removing Roles Immediately is harder. • Token usually is valid until its expiration date. • Token is stored on the client side (by the user). • Mitigations: • Store blacklisted JTI claims (Token Id) in a Db. • Token can grow in size as more fields are added. • Since Token needs to be sent on every request for stateless APIs, it can add to data usage for mobile users.
  • 11. What are Opaque Tokens? • Instead of storing user identity and claims in the token, the opaque token is simply a primary key that references a database entry which has the data. • Fast key value stores like Redis are important for leveraging in memory hash tables for O(1) lookup of the payload.
  • 12. Advantages of Opaque Tokens: • Since the roles are read from a database directly, roles can be changed and the user will see the new roles as soon as the changes propagate through your backend.
  • 13. Disadvantages of Opaque Tokens: • Added complexity of maintaining the K/V store and the auth server. • Each service may have to handshake with the auth server to get the claims or roles.
  • 14. A Blended Strategy • Handle authentication via JWT such as checking that the user is who they say they are. • JWT only handles the authentication side but not authorization side.
  • 15. How to Send Tokens • Avoid URL Query Params: • Because users often copy past and share URLs. • Loggers often record URLs in plain text. • Headers: • ‘Authorization’ Header: Most popular method. • Cookies: • Essentially, when cookie sent to the server, it is just another header.
  • 16. How to Store Tokens on Client Side? Option 1: Cookies • Pros: • Immune to XSS attacks • If set flags to enforce security checks such as HTTP only and Secure. The cookie can’t be read by Javascript. • Cons: • Vulnerable to cross site request forgery (XSRF or CSRF). • Sent for every request, static, AJAX, etc. • Mitigation Strategy: server needs to recognize whether the request came from your real website running in a browser or someone else. • Hidden anti-forgery token • Generate and store a special random key in the cookie
  • 17. How to Store Tokens on Client Side? Option 2: Local Storage • Pros: • Immune to XSRF Attacks. • Cons: • Subject to Cross-Scripting attacks (XSS) • Local Storage is global to your website domain. Thus, any Javascript on your website, 3rd party lib or not, can access the same local storage. • Mitigation: • Ensure the scripts you import into your website are safe. • Can’t access it across multiple subdomains.