SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Securing	
  REST	
  APIs	
  
Les	
  Hazlewood	
  
Apache	
  Shiro	
  Project	
  Chair	
  
CTO,	
  Stormpath	
  
Topics	
  
•  General	
  API	
  Best	
  Prac:ces	
  
•  Statelessness	
  
•  Authen:ca:on	
  
•  Authoriza:on	
  (access	
  control)	
  
General	
  REST	
  API	
  Best	
  Prac=ces	
  
•  Base	
  URL	
  
•  Integer	
  Version	
  
•  HTTP	
  vs	
  HTTPS	
  
•  Nice	
  Error	
  Representa:ons	
  
Base	
  URL	
  +	
  Version	
  
hHps://api.stormpath.com/v1	
  
Error	
  Representa=on	
  
•  HTTP	
  Status	
  Code	
  
•  Applica:on-­‐specific	
  Error	
  Code	
  (18	
  4xx,	
  6	
  5xx)	
  
•  End-­‐user	
  Message	
  
•  Developer	
  Message	
  
•  More	
  Info	
  URL	
  
Error	
  Representa=on	
  Example	
  
HTTP/1.1	
  404	
  Not	
  Found	
  
	
  
{	
  
	
  	
  	
  	
  "status":	
  404,	
  
	
  	
  	
  	
  "code":	
  404,	
  
	
  	
  	
  	
  "message":	
  "Oops!	
  That	
  applica:on	
  cannot	
  be	
  found.",	
  
	
  	
  	
  	
  "developerMessage":	
  "The	
  specified	
  Applica:on	
  cannot	
  be	
  found.	
  	
  
If	
  you	
  accessed	
  this	
  	
  	
  	
  url	
  via	
  a	
  stale	
  href	
  reference,	
  it	
  might	
  be	
  
helpful	
  to	
  acquire	
  the	
  tenant's	
  Applica:on	
  Collec:on	
  Resource	
  to	
  
obtain	
  the	
  current	
  list	
  of	
  applica:ons.",	
  
	
  	
  	
  	
  "moreInfo":	
  "hHp://www.stormpath.com/docs/errors/404"	
  
}	
  
Statelessness	
  
•  No	
  sessions!	
  
Session	
  clustering	
  (and	
  all	
  that	
  it	
  implies)	
  
•  How	
  do	
  you	
  prevent	
  sessions?	
  
Your	
  code?	
  
Framework	
  code?	
  
	
  
NoSessionCreationFilter
[main]
…
[urls]
/v1/** = noSessionCreation, authcBasic, …
	
  
Authen=ca=on	
  
•  What	
  is	
  safe?	
  
•  SSL	
  –	
  server	
  vs	
  client	
  
•  Username/Password,	
  BASIC	
  authen:ca:on	
  
•  API	
  Keys	
  
•  What	
  is	
  OAuth?	
  
HTTP	
  Basic	
  Authen=ca=on	
  
[main]
…
[urls]
/v1/** = ssl, noSessionCreation, authcBasic,
…
	
  
OAuth	
  
•  Protocol	
  
•  Designed	
  for	
  3	
  par:es,	
  can	
  be	
  used	
  for	
  2	
  
•  1.0a	
  vs	
  2.0	
  
•  Signature	
  algorithm	
  (HMAC)	
  
•  Shiro	
  &	
  Scribe	
  
Authoriza=on	
  
•  Filter	
  
•  Excep:on	
  handling	
  
HEpMethodPermissionFilter	
  
[main]
rest = 
org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
[urls]
/v1/user = noSessionCreation, authcBasic, rest[user]
/v1/** = noSessionCreation, authcBasic
Excep=on	
  Handler	
  
•  Annota:on	
  or	
  asser:on	
  
•  MVC	
  framework	
  or	
  JSP	
  ‘catch	
  all’	
  à	
  JSON	
  
@RequiresPermission	
  
public	
  void	
  doSomething()	
  {	
  …}	
  
	
  
subject.checkPermission(“user:read”);	
  

Más contenido relacionado

La actualidad más candente

Securing Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based AuthenticationSecuring Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
Secure Web Services
Secure Web ServicesSecure Web Services
Secure Web Services
Rob Daigneau
 
Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
Igor Bossenko
 
Authentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrongAuthentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrong
Derek Perkins
 
Rest Security with JAX-RS
Rest Security with JAX-RSRest Security with JAX-RS
Rest Security with JAX-RS
Frank Kim
 

La actualidad más candente (20)

Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
Securing Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based AuthenticationSecuring Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based Authentication
 
Secure Web Services
Secure Web ServicesSecure Web Services
Secure Web Services
 
Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
 
Build a Node.js Client for Your REST+JSON API
Build a Node.js Client for Your REST+JSON APIBuild a Node.js Client for Your REST+JSON API
Build a Node.js Client for Your REST+JSON API
 
Authentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrongAuthentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrong
 
Securty Testing For RESTful Applications
Securty Testing For RESTful ApplicationsSecurty Testing For RESTful Applications
Securty Testing For RESTful Applications
 
Rest Security with JAX-RS
Rest Security with JAX-RSRest Security with JAX-RS
Rest Security with JAX-RS
 
REST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTsREST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTs
 
From 0 to Spring Security 4.0
From 0 to Spring Security 4.0From 0 to Spring Security 4.0
From 0 to Spring Security 4.0
 
D@W REST security
D@W REST securityD@W REST security
D@W REST security
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
 
Access Control Pitfalls v2
Access Control Pitfalls v2Access Control Pitfalls v2
Access Control Pitfalls v2
 
Building Layers of Defense with Spring Security
Building Layers of Defense with Spring SecurityBuilding Layers of Defense with Spring Security
Building Layers of Defense with Spring Security
 
Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2
 
ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2
 
Building an API Security Ecosystem
Building an API Security EcosystemBuilding an API Security Ecosystem
Building an API Security Ecosystem
 
Api security
Api security Api security
Api security
 
Building Secure User Interfaces With JWTs
Building Secure User Interfaces With JWTsBuilding Secure User Interfaces With JWTs
Building Secure User Interfaces With JWTs
 

Similar a Securing REST APIs

Secureyourrestapi 140530183606-phpapp02
Secureyourrestapi 140530183606-phpapp02Secureyourrestapi 140530183606-phpapp02
Secureyourrestapi 140530183606-phpapp02
Subhajit Bhuiya
 

Similar a Securing REST APIs (20)

REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Romulus OWASP
Romulus OWASPRomulus OWASP
Romulus OWASP
 
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
SenchaCon 2016: A Look Ahead: Survey Next-Gen Modern Browser APIs - Shikhir S...
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
Elegant Rest Design Webinar
Elegant Rest Design WebinarElegant Rest Design Webinar
Elegant Rest Design Webinar
 
Beautiful REST and JSON APIs - Les Hazlewood
Beautiful REST and JSON APIs - Les HazlewoodBeautiful REST and JSON APIs - Les Hazlewood
Beautiful REST and JSON APIs - Les Hazlewood
 
Secureyourrestapi 140530183606-phpapp02
Secureyourrestapi 140530183606-phpapp02Secureyourrestapi 140530183606-phpapp02
Secureyourrestapi 140530183606-phpapp02
 
A RESTful Interface for Erlang Code using Webmachine
A RESTful Interface for Erlang Code using WebmachineA RESTful Interface for Erlang Code using Webmachine
A RESTful Interface for Erlang Code using Webmachine
 
Intro apache
Intro apacheIntro apache
Intro apache
 
REST API Design for JAX-RS And Jersey
REST API Design for JAX-RS And JerseyREST API Design for JAX-RS And Jersey
REST API Design for JAX-RS And Jersey
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Securing REST APIs

  • 1. Securing  REST  APIs   Les  Hazlewood   Apache  Shiro  Project  Chair   CTO,  Stormpath  
  • 2. Topics   •  General  API  Best  Prac:ces   •  Statelessness   •  Authen:ca:on   •  Authoriza:on  (access  control)  
  • 3. General  REST  API  Best  Prac=ces   •  Base  URL   •  Integer  Version   •  HTTP  vs  HTTPS   •  Nice  Error  Representa:ons  
  • 4. Base  URL  +  Version   hHps://api.stormpath.com/v1  
  • 5. Error  Representa=on   •  HTTP  Status  Code   •  Applica:on-­‐specific  Error  Code  (18  4xx,  6  5xx)   •  End-­‐user  Message   •  Developer  Message   •  More  Info  URL  
  • 6. Error  Representa=on  Example   HTTP/1.1  404  Not  Found     {          "status":  404,          "code":  404,          "message":  "Oops!  That  applica:on  cannot  be  found.",          "developerMessage":  "The  specified  Applica:on  cannot  be  found.     If  you  accessed  this        url  via  a  stale  href  reference,  it  might  be   helpful  to  acquire  the  tenant's  Applica:on  Collec:on  Resource  to   obtain  the  current  list  of  applica:ons.",          "moreInfo":  "hHp://www.stormpath.com/docs/errors/404"   }  
  • 7. Statelessness   •  No  sessions!   Session  clustering  (and  all  that  it  implies)   •  How  do  you  prevent  sessions?   Your  code?   Framework  code?    
  • 9. Authen=ca=on   •  What  is  safe?   •  SSL  –  server  vs  client   •  Username/Password,  BASIC  authen:ca:on   •  API  Keys   •  What  is  OAuth?  
  • 10. HTTP  Basic  Authen=ca=on   [main] … [urls] /v1/** = ssl, noSessionCreation, authcBasic, …  
  • 11. OAuth   •  Protocol   •  Designed  for  3  par:es,  can  be  used  for  2   •  1.0a  vs  2.0   •  Signature  algorithm  (HMAC)   •  Shiro  &  Scribe  
  • 12. Authoriza=on   •  Filter   •  Excep:on  handling  
  • 13. HEpMethodPermissionFilter   [main] rest = org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter [urls] /v1/user = noSessionCreation, authcBasic, rest[user] /v1/** = noSessionCreation, authcBasic
  • 14. Excep=on  Handler   •  Annota:on  or  asser:on   •  MVC  framework  or  JSP  ‘catch  all’  à  JSON   @RequiresPermission   public  void  doSomething()  {  …}     subject.checkPermission(“user:read”);