SlideShare a Scribd company logo
API Security
n|u - The Open security community
Chennai Meet
Presenter : Vinoth Kumar
Date : 20/05/2017
# About Me
Application security engineer.
Blogger @ http://www.tutorgeeks.net
Email @ vinothpkumar333@gmail.com
https://null.co.in/profile/294-vinothpkumar
What is an API
An API is a list of commands that one program can send to another. It is used, so that individual programs can communicate with one
another directly and use each other's functions.
API allows two different application ( built on two different technologies ) communicate with each other.
Eg : A rails application accessing content from Java application and vice versa.
Need for an API
Let’s see the use cases of accessing contents of ā€œwebsite Bā€ ( Using an API vs without an API )
If ā€œwebsite Aā€ wants to access the content in ā€œwebsite Bā€ , it will be difficult, if it fetches the content by parsing the HTML tags, since
website B may have code changes after few months. However, if website B provide API’s well documented, website A can access the
information without much difficulty by looking into the API documentation.
Using an API
Using username and password combination
Curl -v -u username:password -H ā€œContent-type:application/jsonā€ -d ā€˜{JSON Input}’ -X HTTPMethod ā€˜API
Endpoint’
Using API Key
Curl -v -u API Key:test -H ā€œContent-type:application/jsonā€ -d ā€˜{JSON Input}’ -X HTTPMethod ā€˜API Endpoint’
Security issues / Best practices in API
1. XSS / HTML Injection
2. Authorization and Authentication
3. Sensitive information disclosure
4. CORS Misconfiguration
5. API over HTTP
6. CSRF
7. HTTP Verb tampering
XSS and HTML Injection attacks
Vulnerable API Endpoint : api.vimeo.com/channels https://developer.vimeo.com/api/endpoints/channels
Vulnerable parameter : ā€œNameā€ and ā€œdescriptionā€
curl -v -u username:password -H ā€œContent-type:application.jsonā€,
-X POST {'name': '<script>alert(document.cookie)</script>',
'description': '<marquee>HTML Injection</marquee>,
'privacy': 'anybody'}}
Reference : https://hackerone.com/reports/42702
Authorization and Authentication
Case study 1 :
Vulnerable API Endpoint : /api/user/
Login into the application using your valid credentials.
POST /login
{ credentials }
The below API call fetches your profile details
Actual request : GET /api/user/me
Intercept the request and modify the API call.
Modified request : GET /api/user/victim
Fetches the victim details .
Case study 2 :
Update the normal user to admin user. Now, normal user will have admin level privileges.
Now again downgrade back to normal user.
Vulnerability : Normal user still has admin level privileges.
Sensitive information disclosure - H1 Reports API
An attacker can disclose any user's private email by creating a sandbox program then adding that user to a report as a participant. Now
if the attacker issued a request to fetch the report through the API , the response will contain the invited user private email at the
activities object.
Steps to reproduce:
Go to any report submitted to your program.
Add the victim username as a participant to your report.
Generate an API token.
Fetch the report through the API
curl "https://api.hackerone.com/v1/reports/[report_id]" -u "api_idetifier:token"
The response will contain the invited user email at the activities object:
"activities":{"data":[{"type":"activity-external-user-invited","id":"1406712","attributes":{"message":null,"created_at":"2017-01-
08T01:57:27.614Z","updated_at":"2017-01-08T01:57:27.614Z","internal":true,"email":"<victim's_email@example.com>"}
Reference : https://hackerone.com/reports/196655
CORS Misconfiguration
Image, in example.com, we have the following header in the configuration
Access-Control-Allow-Origin: hello.com
www.evil.com wants to access the content in example.com
Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.example.com/. This can be fixed by
moving the resource to the same domain or enabling CORS.
Vulnerable CORS setting.
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
If the victim is logged into the application, the attacker can send an XMLHttpRequest to fetch the details.
Reference : http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html
API’s over HTTP
Vulnerable Request : curl -v -u username:password -H "Content-Type: application/json" -X GET
'http://example.com/api/vinoth/creditcard'
Imaging, the above API request is returning the credit card details of vinoth in response.
{ā€œcredit cardā€ : 1111 1111 1111 1111, ā€œexpiry dateā€: ā€œ09/37ā€, ā€œCVVā€: 343 }
However, if you notice the above API call, it is accepting HTTP endpoint. Hence, it is vulnerable to sniffing attacks.
Remediation : All API requests should hit the secured endpoint i.e. only HTTPS
curl -v -u username:password -H "Content-Type: application/json" -X GET 'https://example.com/api/vinoth/creditcard'
CSRF - Twitter Cards API
POST
https://twitter.com/i/cards/api/v1.json?tweet_id=657629231309041664&card_name=poll2choice_text_only&forward=false&capi_uri=capi%3A%2F
%2Fpassthrough%2F1 HTTP/1.1
Host: twitter.com
Cookie: foo=bar
{"twitter:string:card_uri":"card://657629230759415808","twitter:long:original_tweet_id":"657629231309041664","twitter:string:selected_choice":"2
"}
POST
https://twitter.com/i/cards/api/v1?tweet_id=657629231309041664&card_name=poll2choice_text_only&forward=false&capi_uri=capi%3A%2F%2F
passthrough%2F1 HTTP/1.1
Host: twitter.com
Cookie: foo=bar
{"twitter:string:card_uri":"card://657629230759415808","twitter:long:original_tweet_id":"657629231309041664","twitter:string:selected_choice":"2
"}
Reference : https://hackerone.com/reports/95555
HTTP Verb tampering
HTTP Verb tampering : Trying random HTTP Methods.
API’s often use GET (read), POST (create), PUT (replace/update) and DELETE (to delete a record). Not all of these are valid choices
for every single resource collection, user, or action.
Make sure the incoming HTTP method is valid for the session token/API key and associated resource collection, action, and record.
For example, if you have an RESTful API for a library, it's not okay to allow anonymous users to DELETE book catalog entries, but it's
fine for them to GET a book catalog entry. On the other hand, for the librarian, both of these are valid uses.
Fuzzing - Array worth $500
Generates totally random input for the specified request parameters, hoping to provoke some kind of unexpected results.
Eg : If the API expects a string parameter , input an integer and vice-versa and check how the system responds.
Fuzzing IRCloud API’s
A security researcher discovered an API payload that would send invalid data to their own user process, which would repeatedly fail to
be handled correctly. This error handling loop prevented further access to their user account.
Actual request : {ā€œ_reqidā€:1234, ā€œcidā€:5678, ā€œtoā€: ā€œ#treehouseā€, ā€œmsgā€:ā€testā€, ā€œmethodā€:ā€sayā€}
Modified request : {ā€œ_reqidā€:1234, ā€œcidā€:5678, ā€œtoā€:[ā€œ#treehouseā€, ā€œ#darkscienceā€] , ā€œmsgā€:ā€testā€, ā€œmethodā€:ā€sayā€}
Reference : https://www.intelisecure.com/fuzzing-for-fun-and-profit/
API Rate limiting
X-RateLimit-Limit – The limit that you cannot surpass in a given amount of time
X-RateLimit-Remaining – The number of calls you have available until a given reset time stamp, or calculated given some sort of
sliding time window.
X-RateLimit-Reset – The timestamp in UTC formatted to HTTP spec per RFC 1123 for when the limits will be reset.
If you exceed the provided rate limit for a given API endpoint, you will receive the 429 Too Many Requests response with the
following message:
{
"message": "Too many requests. Check the X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers."
}
API Key - Compromise
It’s always better to mask your API key.
If the account is compromised , the attacker can note down your API key. This is dangerous, because even if the victim
changes his password realising the account compromise, the attacker can still have access to the account using his API
key.
Incase of account compromise, don’t just change the password, reset your API key as well.
API Testing tools
Postman
https://www.getpostman.com/
Fuzzapi [ REST API - JSON ]
https://github.com/nkpanda/fuzzapi
SOAPUI
https://www.soapui.org
Ready API
https://smartbear.com/product/ready-api/overview/
Tips for API Security assessment
API Documentation of the target is the main source for your assessment.
OWASP API Security cheat sheets can be handy
https://www.owasp.org/index.php/OWASP_API_Security_Project
https://www.owasp.org/index.php/REST_Assessment_Cheat_Sheet
https://www.owasp.org/index.php/OWASP_SaaS_Rest_API_Secure_Guide
Thank You

More Related Content

What's hot (20)

PPTX
OAuth2 + API Security
Amila Paranawithana
Ā 
PDF
OAuth - Open API Authentication
leahculver
Ā 
PDF
Stateless authentication for microservices
Alvaro Sanchez-Mariscal
Ā 
PDF
Stateless authentication for microservices - GR8Conf 2015
Alvaro Sanchez-Mariscal
Ā 
PPTX
Securing RESTful APIs using OAuth 2 and OpenID Connect
Jonathan LeBlanc
Ā 
PPTX
Secure Your REST API (The Right Way)
Stormpath
Ā 
PPTX
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
Ā 
PDF
The Ultimate Guide to Mobile API Security
Stormpath
Ā 
PPTX
API Security from the DevOps and CSO Perspectives (Webcast)
Apigee | Google Cloud
Ā 
PDF
JavaOne 2014 - Securing RESTful Resources with OAuth2
Rodrigo CĆ¢ndido da Silva
Ā 
PDF
Ruby on Rails Security Guide
ihji
Ā 
PPTX
Securing your apps with OAuth2 and OpenID Connect - Roland Guijt - Codemotion...
Codemotion
Ā 
PPTX
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
Stuart
Ā 
PPTX
Single-Page-Application & REST security
Igor Bossenko
Ā 
PPT
Ruby Security
SHC
Ā 
PPTX
Token Authentication for Java Applications
Stormpath
Ā 
ODP
OAuth2 - Introduction
Knoldus Inc.
Ā 
PDF
API Security Best Practices & Guidelines
Prabath Siriwardena
Ā 
PDF
Watch How the Giants Fall
jtmelton
Ā 
PPTX
D@W REST security
Gaurav Sharma
Ā 
OAuth2 + API Security
Amila Paranawithana
Ā 
OAuth - Open API Authentication
leahculver
Ā 
Stateless authentication for microservices
Alvaro Sanchez-Mariscal
Ā 
Stateless authentication for microservices - GR8Conf 2015
Alvaro Sanchez-Mariscal
Ā 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Jonathan LeBlanc
Ā 
Secure Your REST API (The Right Way)
Stormpath
Ā 
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
Ā 
The Ultimate Guide to Mobile API Security
Stormpath
Ā 
API Security from the DevOps and CSO Perspectives (Webcast)
Apigee | Google Cloud
Ā 
JavaOne 2014 - Securing RESTful Resources with OAuth2
Rodrigo CĆ¢ndido da Silva
Ā 
Ruby on Rails Security Guide
ihji
Ā 
Securing your apps with OAuth2 and OpenID Connect - Roland Guijt - Codemotion...
Codemotion
Ā 
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
Stuart
Ā 
Single-Page-Application & REST security
Igor Bossenko
Ā 
Ruby Security
SHC
Ā 
Token Authentication for Java Applications
Stormpath
Ā 
OAuth2 - Introduction
Knoldus Inc.
Ā 
API Security Best Practices & Guidelines
Prabath Siriwardena
Ā 
Watch How the Giants Fall
jtmelton
Ā 
D@W REST security
Gaurav Sharma
Ā 

Viewers also liked (7)

PPTX
Nmap and metasploitable
Mohammed Akbar Shariff
Ā 
PPSX
Bit squatting
Avradeep Bhattacharya
Ā 
PDF
A Strategic Path from Secure Code Reviews to Threat Modeling (101)
Deepam Kanjani
Ā 
PPTX
Metasploit framwork
Deepanshu Gajbhiye
Ā 
PDF
Yet another talk on bug bounty
vinoth kumar
Ā 
PDF
Networking basics by rahul at Null Mumbai
Avkash Kathiriya
Ā 
PPTX
Basics of Cryptography
Sunil Kumar
Ā 
Nmap and metasploitable
Mohammed Akbar Shariff
Ā 
Bit squatting
Avradeep Bhattacharya
Ā 
A Strategic Path from Secure Code Reviews to Threat Modeling (101)
Deepam Kanjani
Ā 
Metasploit framwork
Deepanshu Gajbhiye
Ā 
Yet another talk on bug bounty
vinoth kumar
Ā 
Networking basics by rahul at Null Mumbai
Avkash Kathiriya
Ā 
Basics of Cryptography
Sunil Kumar
Ā 
Ad

Similar to API Security - Null meet (20)

PDF
Web Apps: APIs' Nightmare
Paulo Silva
Ā 
PDF
LF_APIStrat17_OWASP’s Latest Category: API Underprotection
LF_APIStrat
Ā 
PDF
apidays New York 2023 - Android Applications and APIs Hacking, Gabrielle Botb...
apidays
Ā 
PPTX
API Workshop: Deep dive into REST APIs
Tom Johnson
Ā 
PDF
Apidays Paris 2023 - Securing Microservice-based APIs, Michal Trojanowski, Cu...
apidays
Ā 
PDF
Top 10 Web App Security Risks
Sperasoft
Ā 
PDF
HowYourAPIBeMyAPI
Jie Liau
Ā 
PDF
Application Server-less Web Applications - Serverless Toronto Meetup
Daniel Zivkovic
Ā 
PDF
testupload
admiralderp
Ā 
PDF
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
CA API Management
Ā 
PDF
Federation Evolved: How Cloud, Mobile & APIs Change the Way We Broker Identity
CA API Management
Ā 
PDF
5 step plan to securing your APIs
šŸ’» Javier Garza
Ā 
PPTX
Z101666 best practices for delivering hybrid cloud capability with apis
Teodoro Cipresso
Ā 
PPTX
How to build Simple yet powerful API.pptx
Channa Ly
Ā 
PDF
Web PenTest Sample Report
Octogence
Ā 
PDF
APIsecure 2023 - Breaking Vulnerable APIs, Tushar Kulkarni
apidays
Ā 
PDF
WEBINAR: OWASP API Security Top 10
42Crunch
Ā 
PDF
Protecting Microservices APIs with 42Crunch API Firewall
42Crunch
Ā 
PDF
OWASP API Security Top 10 - Austin DevSecOps Days
42Crunch
Ā 
PDF
RefCard RESTful API Design
OCTO Technology
Ā 
Web Apps: APIs' Nightmare
Paulo Silva
Ā 
LF_APIStrat17_OWASP’s Latest Category: API Underprotection
LF_APIStrat
Ā 
apidays New York 2023 - Android Applications and APIs Hacking, Gabrielle Botb...
apidays
Ā 
API Workshop: Deep dive into REST APIs
Tom Johnson
Ā 
Apidays Paris 2023 - Securing Microservice-based APIs, Michal Trojanowski, Cu...
apidays
Ā 
Top 10 Web App Security Risks
Sperasoft
Ā 
HowYourAPIBeMyAPI
Jie Liau
Ā 
Application Server-less Web Applications - Serverless Toronto Meetup
Daniel Zivkovic
Ā 
testupload
admiralderp
Ā 
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
CA API Management
Ā 
Federation Evolved: How Cloud, Mobile & APIs Change the Way We Broker Identity
CA API Management
Ā 
5 step plan to securing your APIs
šŸ’» Javier Garza
Ā 
Z101666 best practices for delivering hybrid cloud capability with apis
Teodoro Cipresso
Ā 
How to build Simple yet powerful API.pptx
Channa Ly
Ā 
Web PenTest Sample Report
Octogence
Ā 
APIsecure 2023 - Breaking Vulnerable APIs, Tushar Kulkarni
apidays
Ā 
WEBINAR: OWASP API Security Top 10
42Crunch
Ā 
Protecting Microservices APIs with 42Crunch API Firewall
42Crunch
Ā 
OWASP API Security Top 10 - Austin DevSecOps Days
42Crunch
Ā 
RefCard RESTful API Design
OCTO Technology
Ā 
Ad

Recently uploaded (20)

PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
Ā 
PPTX
The Human Eye and The Colourful World Class 10 NCERT Science.pptx
renutripathibharat
Ā 
PPTX
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
Ā 
PPTX
How to Manage Access Rights & User Types in Odoo 18
Celine George
Ā 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
Ā 
PDF
BƀI Tįŗ¬P Bį»” TRỢ THEO LESSON TIįŗ¾NG ANH - I-LEARN SMART WORLD 7 - Cįŗ¢ NĂM - CƓ ĐƁ...
Nguyen Thanh Tu Collection
Ā 
PPTX
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
Ā 
PDF
07.15.2025 - Managing Your Members Using a Membership Portal.pdf
TechSoup
Ā 
PPTX
nutriquiz grade 4.pptx...............................................
ferdinandsanbuenaven
Ā 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
Ā 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
Ā 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
Ā 
PDF
CONCURSO DE POESIA ā€œPOETUFAS – PASSOS SUAVES PELO VERSO.pdf
ColƩgio Santa Teresinha
Ā 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
Ā 
PPTX
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
Ā 
PPTX
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
Ā 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
Ā 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
Ā 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
Ā 
PPTX
SAMPLING: DEFINITION,PROCESS,TYPES,SAMPLE SIZE, SAMPLING ERROR.pptx
PRADEEP ABOTHU
Ā 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
Ā 
The Human Eye and The Colourful World Class 10 NCERT Science.pptx
renutripathibharat
Ā 
Blanket Order in Odoo 17 Purchase App - Odoo Slides
Celine George
Ā 
How to Manage Access Rights & User Types in Odoo 18
Celine George
Ā 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
Ā 
BƀI Tįŗ¬P Bį»” TRỢ THEO LESSON TIįŗ¾NG ANH - I-LEARN SMART WORLD 7 - Cįŗ¢ NĂM - CƓ ĐƁ...
Nguyen Thanh Tu Collection
Ā 
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
Ā 
07.15.2025 - Managing Your Members Using a Membership Portal.pdf
TechSoup
Ā 
nutriquiz grade 4.pptx...............................................
ferdinandsanbuenaven
Ā 
digestive system for Pharm d I year HAP
rekhapositivity
Ā 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
Ā 
PPT on the Development of Education in the Victorian England
Beena E S
Ā 
CONCURSO DE POESIA ā€œPOETUFAS – PASSOS SUAVES PELO VERSO.pdf
ColƩgio Santa Teresinha
Ā 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
Ā 
classroom based quiz bee.pptx...................
ferdinandsanbuenaven
Ā 
Maternal and Child Tracking system & RCH portal
Ms Usha Vadhel
Ā 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
Ā 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
Ā 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
Ā 
SAMPLING: DEFINITION,PROCESS,TYPES,SAMPLE SIZE, SAMPLING ERROR.pptx
PRADEEP ABOTHU
Ā 

API Security - Null meet

  • 1. API Security n|u - The Open security community Chennai Meet Presenter : Vinoth Kumar Date : 20/05/2017
  • 2. # About Me Application security engineer. Blogger @ http://www.tutorgeeks.net Email @ [email protected] https://null.co.in/profile/294-vinothpkumar
  • 3. What is an API An API is a list of commands that one program can send to another. It is used, so that individual programs can communicate with one another directly and use each other's functions. API allows two different application ( built on two different technologies ) communicate with each other. Eg : A rails application accessing content from Java application and vice versa. Need for an API Let’s see the use cases of accessing contents of ā€œwebsite Bā€ ( Using an API vs without an API ) If ā€œwebsite Aā€ wants to access the content in ā€œwebsite Bā€ , it will be difficult, if it fetches the content by parsing the HTML tags, since website B may have code changes after few months. However, if website B provide API’s well documented, website A can access the information without much difficulty by looking into the API documentation.
  • 4. Using an API Using username and password combination Curl -v -u username:password -H ā€œContent-type:application/jsonā€ -d ā€˜{JSON Input}’ -X HTTPMethod ā€˜API Endpoint’ Using API Key Curl -v -u API Key:test -H ā€œContent-type:application/jsonā€ -d ā€˜{JSON Input}’ -X HTTPMethod ā€˜API Endpoint’
  • 5. Security issues / Best practices in API 1. XSS / HTML Injection 2. Authorization and Authentication 3. Sensitive information disclosure 4. CORS Misconfiguration 5. API over HTTP 6. CSRF 7. HTTP Verb tampering
  • 6. XSS and HTML Injection attacks Vulnerable API Endpoint : api.vimeo.com/channels https://developer.vimeo.com/api/endpoints/channels Vulnerable parameter : ā€œNameā€ and ā€œdescriptionā€ curl -v -u username:password -H ā€œContent-type:application.jsonā€, -X POST {'name': '<script>alert(document.cookie)</script>', 'description': '<marquee>HTML Injection</marquee>, 'privacy': 'anybody'}} Reference : https://hackerone.com/reports/42702
  • 7. Authorization and Authentication Case study 1 : Vulnerable API Endpoint : /api/user/ Login into the application using your valid credentials. POST /login { credentials } The below API call fetches your profile details Actual request : GET /api/user/me Intercept the request and modify the API call. Modified request : GET /api/user/victim Fetches the victim details . Case study 2 : Update the normal user to admin user. Now, normal user will have admin level privileges. Now again downgrade back to normal user. Vulnerability : Normal user still has admin level privileges.
  • 8. Sensitive information disclosure - H1 Reports API An attacker can disclose any user's private email by creating a sandbox program then adding that user to a report as a participant. Now if the attacker issued a request to fetch the report through the API , the response will contain the invited user private email at the activities object. Steps to reproduce: Go to any report submitted to your program. Add the victim username as a participant to your report. Generate an API token. Fetch the report through the API curl "https://api.hackerone.com/v1/reports/[report_id]" -u "api_idetifier:token" The response will contain the invited user email at the activities object: "activities":{"data":[{"type":"activity-external-user-invited","id":"1406712","attributes":{"message":null,"created_at":"2017-01- 08T01:57:27.614Z","updated_at":"2017-01-08T01:57:27.614Z","internal":true,"email":"<victim'[email protected]>"} Reference : https://hackerone.com/reports/196655
  • 9. CORS Misconfiguration Image, in example.com, we have the following header in the configuration Access-Control-Allow-Origin: hello.com www.evil.com wants to access the content in example.com Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.example.com/. This can be fixed by moving the resource to the same domain or enabling CORS. Vulnerable CORS setting. Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true If the victim is logged into the application, the attacker can send an XMLHttpRequest to fetch the details. Reference : http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html
  • 10. API’s over HTTP Vulnerable Request : curl -v -u username:password -H "Content-Type: application/json" -X GET 'http://example.com/api/vinoth/creditcard' Imaging, the above API request is returning the credit card details of vinoth in response. {ā€œcredit cardā€ : 1111 1111 1111 1111, ā€œexpiry dateā€: ā€œ09/37ā€, ā€œCVVā€: 343 } However, if you notice the above API call, it is accepting HTTP endpoint. Hence, it is vulnerable to sniffing attacks. Remediation : All API requests should hit the secured endpoint i.e. only HTTPS curl -v -u username:password -H "Content-Type: application/json" -X GET 'https://example.com/api/vinoth/creditcard'
  • 11. CSRF - Twitter Cards API POST https://twitter.com/i/cards/api/v1.json?tweet_id=657629231309041664&card_name=poll2choice_text_only&forward=false&capi_uri=capi%3A%2F %2Fpassthrough%2F1 HTTP/1.1 Host: twitter.com Cookie: foo=bar {"twitter:string:card_uri":"card://657629230759415808","twitter:long:original_tweet_id":"657629231309041664","twitter:string:selected_choice":"2 "} POST https://twitter.com/i/cards/api/v1?tweet_id=657629231309041664&card_name=poll2choice_text_only&forward=false&capi_uri=capi%3A%2F%2F passthrough%2F1 HTTP/1.1 Host: twitter.com Cookie: foo=bar {"twitter:string:card_uri":"card://657629230759415808","twitter:long:original_tweet_id":"657629231309041664","twitter:string:selected_choice":"2 "} Reference : https://hackerone.com/reports/95555
  • 12. HTTP Verb tampering HTTP Verb tampering : Trying random HTTP Methods. API’s often use GET (read), POST (create), PUT (replace/update) and DELETE (to delete a record). Not all of these are valid choices for every single resource collection, user, or action. Make sure the incoming HTTP method is valid for the session token/API key and associated resource collection, action, and record. For example, if you have an RESTful API for a library, it's not okay to allow anonymous users to DELETE book catalog entries, but it's fine for them to GET a book catalog entry. On the other hand, for the librarian, both of these are valid uses.
  • 13. Fuzzing - Array worth $500 Generates totally random input for the specified request parameters, hoping to provoke some kind of unexpected results. Eg : If the API expects a string parameter , input an integer and vice-versa and check how the system responds. Fuzzing IRCloud API’s A security researcher discovered an API payload that would send invalid data to their own user process, which would repeatedly fail to be handled correctly. This error handling loop prevented further access to their user account. Actual request : {ā€œ_reqidā€:1234, ā€œcidā€:5678, ā€œtoā€: ā€œ#treehouseā€, ā€œmsgā€:ā€testā€, ā€œmethodā€:ā€sayā€} Modified request : {ā€œ_reqidā€:1234, ā€œcidā€:5678, ā€œtoā€:[ā€œ#treehouseā€, ā€œ#darkscienceā€] , ā€œmsgā€:ā€testā€, ā€œmethodā€:ā€sayā€} Reference : https://www.intelisecure.com/fuzzing-for-fun-and-profit/
  • 14. API Rate limiting X-RateLimit-Limit – The limit that you cannot surpass in a given amount of time X-RateLimit-Remaining – The number of calls you have available until a given reset time stamp, or calculated given some sort of sliding time window. X-RateLimit-Reset – The timestamp in UTC formatted to HTTP spec per RFC 1123 for when the limits will be reset. If you exceed the provided rate limit for a given API endpoint, you will receive the 429 Too Many Requests response with the following message: { "message": "Too many requests. Check the X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers." }
  • 15. API Key - Compromise It’s always better to mask your API key. If the account is compromised , the attacker can note down your API key. This is dangerous, because even if the victim changes his password realising the account compromise, the attacker can still have access to the account using his API key. Incase of account compromise, don’t just change the password, reset your API key as well.
  • 16. API Testing tools Postman https://www.getpostman.com/ Fuzzapi [ REST API - JSON ] https://github.com/nkpanda/fuzzapi SOAPUI https://www.soapui.org Ready API https://smartbear.com/product/ready-api/overview/
  • 17. Tips for API Security assessment API Documentation of the target is the main source for your assessment. OWASP API Security cheat sheets can be handy https://www.owasp.org/index.php/OWASP_API_Security_Project https://www.owasp.org/index.php/REST_Assessment_Cheat_Sheet https://www.owasp.org/index.php/OWASP_SaaS_Rest_API_Secure_Guide