NOTES:
-
APIs are transparent
-
Types of APIs:
- Private
- Public
- Partner
-
API security Domain:
-
Portal - publishes keys for the API (Keys are published on these portals and used by Developers to develop applications)
-
API - Allows granular-level access to systems and productivity tools
-
Application - uses the API to communicate with the microservices
-
User - use the app that interacts with API or uses API to communicate with the microservices
-
Developer - uses the API to develop an application
-
Admin - produces and maintains the APIs.
-
API vulnerability will provide a more diverse and granular level of access to the server as compared to a compromised application or website.
-
Private APIs can be visible to public internet if not secured properly, private doesn’t mean secure.
-
TOP 10 OWASP 2024(not updated since last update 2023) https://owasp.org/API-Security/editions/2023/en/0x11-t10/:
- Broken object level authorization - Object-level authorization (OLA) is an access control mechanism that determines which users can perform actions on specific data objects in an application. (mitigation - Object level authorization checks on functions accessing a data source using an ID from the user)
- Broken Authentication - implementation flaws to assume other users identitites temp or permanently.
- Brokern Object property level Authorization - combines excessive data exposure and mass assignment, Object property level authorization (OPLA) is a security control that allows administrators to limit access to specific object properties or attributes based on user roles or permissions.
- Unrestricted Resource Consumption - mitigation a rate limit mechanism should be implemented
- Broken Function level Authorizatoion - Complex access control policies with different hierarchies, groups, and roles, and an unclear separation between administrative and regular functions, tend to lead to authorization flaws.
- Unrestricted Access to sensitive business flows - APIs vulnerable to this risk expose a business flow - such as buying a ticket, or posting a comment - without compensating for how the functionality could harm the business if used excessively in an automated manner.
- server side request forgery - Server-Side Request Forgery (SSRF) flaws can occur when an API is fetching a remote resource without validating the user-supplied URI.
- security misconfigurations - APIs and the systems supporting them typically contain complex configurations, meant to make the APIs more customizable.
- improper inventory management - APIs tend to expose more endpoints than traditional web applications, making proper and updated documentation highly important.
- unsafe consumption of APIs - Developers tend to trust data received from third-party APIs more than user input, and so tend to adopt weaker security standards.
-
Mitigating API threats:
- Rate limiting - limits the amount of time a service can be requested.
- Message validation - validates incoming and outgoing messages (messages are usually JSON containing functions that is a way to communicate with APIs)
- Access control - restricts API usage based on identity
- Encryption - MITM and spoofing are mitigated
- OpeinID connect and OAuth have been introduced for authentication and SSL/TLS has been implemented to enable encryption of communication channel.
- TLS trust attack:
- CA vuln:
- trusted CA compromised and is used to issue malicious certificates.
- Human Vuln:
- weakest link
- MITM:
- if the channel is using vulnerable ssl/tls protocol, the coomunication can be sniffed and the packets can be decoded with a amount of experience
- CA vuln:
- HTTP access control:
- basic authentication - request header contains password and username in plaintext which is base64 encoded (there is difference between encoding and encrypting) encoding doesn’t mean it is secure and confidential, it means that the data is obfuscated.
- Digest authentication - password is encrypted, server can downgrade the scheme to basic, vuln to man in the middle attack.
-
Best security practices:
- authentication and authorization of users
- check for OWASP top 10 vulnerabilities
- Throttling (rate limiting the services)
- Continuous API monitoring to detect over-usage
- Request/response payload validation
- Error handling (to prevent unwanted information disclosure)
OAuth2:
- An authorization protocol that authorizes a user without sharing a username and password, a Oauth access token is issued and accepted for an authorized user at an API endpoint.
- Access controls:
- traditional access controls are built in such a way that they assume there are two parties involved and access controls are planned assuming two parties.
- These access controls are ineffective in the case of APIs. To illustrate an external developer develops an app using the API users do not trust the external developer to share their credentials to utilize the API, this kind of trust problems can be solved with the help of OAuth.
- Oauth prescribes a standardize way to access 3rd party resources in a secure and authorized way.
- Code flow for OAuth:
- App registers and authenticates and authorizes itself with the provider to get access to API services
- API needs to know the application name and callback URL for redirections.
- API provides the app with clientID(Public identifier encoded in multicharacter hex string) and client secret (Known only to the authorization API server and app, secret is a 256bit value that is converted to corresponding hex value by encryption)
- resource scope determines what kind of access an app has over the API services
- The authorization server can be owned by the service provider or general service providers like (google, Facebook, LinkedIn, etc) and the resource server is owned by the service provider.
- Scopes are used to restrict the use of API functionalities.
- Example: if the account is only authorized to read from the resources it should only read from the service and not write to it.
- e.g of an OAuth token : https://piggybank.com/login/oauth/authorize?client-id=****************************scope=transact_hist acct_bal acct_trnsf
- Good API documentation should contain all the scopes of an API service and how to utilize them.
- OAuth is not an authentication service.
- OAuth2 - 4 grant types:
- Authorization code(scoped access to a resource server):
- authorization code is exchanged for an access token
- resource owner credentials remain confidential
- The access token is never shared with the resource owner
- complex implementation
- Implicit(Javascript single page application):
- the client is issued an access token directly in the return URL
- simple but not secure needs custom security implementations in the client app.
- Resource Owner Password Credentials(only used in a high degree of trust environment):
- Only a username and password are required
- This kind of grant gives the ability to impersonate the resource owner.
- use only in emergencies.
- Client Credentials(non interactive apps):
- authorization scope is limited to protected resources under clients’ control or previously arranged with the authorization server.
- only be used for confidential clients or internal clients.
- Authorization code(scoped access to a resource server):
- OpenID:
- Identity is a set of attributes, one can have many attributes
- OpenID compliments OAuth by introducing an identity resource that will authenticate a user.
- openID connect provides authorized access to identity.
- ID token- acts like an encrypted fingerprint that can be decoded to reveal user information for identity verification
- OpenID with OAuth2:
- The app makes a request to the authorization server by providing the app name and call back URL, the authorization server returns an ID token and access token to authenticate and authorize the user.
- these tokens are then exchanged with the resource server to authenticate and authorize itself.
- user info claims - return claims about already authenticated user
- JSON Web Tokens (JWT):
- compact and self-contained way of securely transmitting information between parties.
- A part of javascript object signing and encryption.
- JWT token → JWS (Signed JWT for integrity using the private key of the authorization server) → JWE (signed JWT is encrypted for confidentiality using the public key of recipient) → JWK (JWT containing cryptographic keys) → JWA (Defines what algorithm is being used for encryption)
- Anatomy of JWT:
- header - contains algorithm used to produce signature, key identifiers.
- payload - contains a set of claims example issuer of token, came of the subject, and other attributes.
- signature - encoding algorithm included in the header.
- characteristics of JWT:
- claim based:
- authorization
- authentication
- Portability:
- stored on client
- flexible and extensive
- message level encryption
- message level signature
- media type
- limited size
- reduce confusion
- verbosity and concise
- stateful ( token won’t be encrypted) vs stateless (token will be encrypted)
- format for refresh, id, and access token.
- claim based:
- Challenges:
- token revocation
- vulnerabilities
- performance and overhead
- Threat to OAuth2:
- Client threat:
- obtaining client secrets
- obtaining refresh tokens
- obtaining access tokens
- phishing using a compromised embedded browser
- open redirect on client
- mitigations:
- application access control - cred validation should be performed on server side, implement continuous monitoring and detection and sharing the client id and secret while handshake.
- Endpoint Threat:
- server impersonation
- mitigation - certificate pinning, using out of band certificate validation.
- redirection hijack
- mitigation - proof key for code exchange
- Token threat:
- eavesdropping access token
- obtaining access tokens from the authorization server database
- disclosure of client credentials during transmission
- obtaining client secrets from the authorization server database
- obtaining client secrets by guessing
- Mitigations - token binding
- Client threat:
-
Course Registration:
The course is self paced and takes only 4 hours to complete, very easy to understand needs a bit of practice to fully grasp it but is possible if you are fully dedicated.
Feel free to reach out if you need any help
Exam Pattern:
The test is un timed and there are no proctores, the questions are fully focused towards what you have learned throughout the course.