- Injection. Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker's hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization.
- Broken Authentication. Application functions related to authentication and session management are often implemented incorrectly, allowing attackers to compromise passwords, keys, or session tokens, or to exploit other implementation flaws to assume other users' identities temporarily or permanently.
- Sensitive Data Exposure. Many web applications and APIs do not properly protect sensitive data, such as financial, healthcare, and PII. Attackers may steal or modify such weakly protected data to conduct credit card fraud, identity theft, or other crimes. Sensitive data may be compromised without extra protection, such as encryption at rest or in transit, and requires special precautions when exchanged with the browser.
- XML External Entities (XXE). Many older or poorly configured XML processors evaluate external entity references within XML documents. External entities can be used to disclose internal files using the file URI handler, internal file shares, internal port scanning, remote code execution, and denial of service attacks.
- Broken Access Control. Restrictions on what authenticated users are allowed to do are often not properly enforced. Attackers can exploit these flaws to access unauthorized functionality and/or data, such as access other users' accounts, view sensitive files, modify other users' data, change access rights, etc.
- Security Misconfiguration. Security misconfiguration is the most commonly seen issue. This is commonly a result of insecure default configurations, incomplete or ad hoc configurations, open cloud storage, misconfigured HTTP headers, and verbose error messages containing sensitive information. Not only must all operating systems, frameworks, libraries, and applications be securely configured, but they must be patched/upgraded in a timely fashion.
- Cross-Site Scripting XSS. XSS flaws occur whenever an application includes untrusted data in a new web page without proper validation or escaping, or updates an existing web page with user-supplied data using a browser API that can create HTML or JavaScript. XSS allows attackers to execute scripts in the victim's browser which can hijack user sessions, deface web sites, or redirect the user to malicious sites.
- Insecure Deserialization. Insecure deserialization often leads to remote code execution. Even if deserialization flaws do not result in remote code execution, they can be used to perform attacks, including replay attacks, injection attacks, and privilege escalation attacks.
- Using Components with Known Vulnerabilities. Components, such as libraries, frameworks, and other software modules, run with the same privileges as the application. If a vulnerable component is exploited, such an attack can facilitate serious data loss or server takeover. Applications and APIs using components with known vulnerabilities may undermine application defenses and enable various attacks and impacts.
- Insufficient Logging & Monitoring. Insufficient logging and monitoring, coupled with missing or ineffective integration with incident response, allows attackers to further attack systems, maintain persistence, pivot to more systems, and tamper, extract, or destroy data. Most breach studies show time to detect a breach is over 200 days, typically detected by external parties rather than internal processes or monitoring.
Blog about knowledge sharing and key points about tech concepts.
Search This Blog
Monday, August 3, 2020
Top 10 Web Application Security Risks
API Security Checklist Points
Checklist of the most important security countermeasures when designing, testing, and releasing your API.
Authentication
- Don't use
Basic Auth
. Use standard authentication instead (e.g. JWT, OAuth). - Don't reinvent the wheel in
Authentication
,token generation
,password storage
. Use the standards. - Use
Max Retry
and jail features in Login. - Use encryption on all sensitive data.
JWT (JSON Web Token)
- Use a random complicated key (
JWT Secret
) to make brute forcing the token very hard. - Don't extract the algorithm from the header. Force the algorithm in the backend (
HS256
orRS256
). - Make token expiration (
TTL
,RTTL
) as short as possible. - Don't store sensitive data in the JWT payload, it can be decoded easily.
OAuth
- Always validate
redirect_uri
server-side to allow only whitelisted URLs. - Always try to exchange for code and not tokens (don't allow
response_type=token
). - Use
state
parameter with a random hash to prevent CSRF on the OAuth authentication process. - Define the default scope, and validate scope parameters for each application.
Access
- Limit requests (Throttling) to avoid DDoS / brute-force attacks.
- Use HTTPS on server side to avoid MITM (Man in the Middle Attack).
- Use
HSTS
header with SSL to avoid SSL Strip attack.
Input
- Use the proper HTTP method according to the operation:
GET (read)
,POST (create)
,PUT/PATCH (replace/update)
, andDELETE (to delete a record)
, and respond with405 Method Not Allowed
if the requested method isn't appropriate for the requested resource. - Validate
content-type
on request Accept header (Content Negotiation) to allow only your supported format (e.g.application/xml
,application/json
, etc.) and respond with406 Not Acceptable
response if not matched. - Validate
content-type
of posted data as you accept (e.g.application/x-www-form-urlencoded
,multipart/form-data
,application/json
, etc.). - Validate user input to avoid common vulnerabilities (e.g.
XSS
,SQL-Injection
,Remote Code Execution
, etc.). - Don't use any sensitive data (
credentials
,Passwords
,security tokens
, orAPI keys
) in the URL, but use standard Authorization header. - Use an API Gateway service to enable caching, Rate Limit policies (e.g.
Quota
,Spike Arrest
, orConcurrent Rate Limit
) and deploy APIs resources dynamically.
Processing
- Check if all the endpoints are protected behind authentication to avoid broken authentication process.
- User own resource ID should be avoided. Use
/me/orders
instead of/user/654321/orders
. - Don't auto-increment IDs. Use
UUID
instead. - If you are parsing XML files, make sure entity parsing is not enabled to avoid
XXE
(XML external entity attack). - If you are parsing XML files, make sure entity expansion is not enabled to avoid
Billion Laughs/XML bomb
via exponential entity expansion attack. - Use a CDN for file uploads.
- If you are dealing with huge amount of data, use Workers and Queues to process as much as possible in background and return response fast to avoid HTTP Blocking.
- Do not forget to turn the DEBUG mode OFF.
Output
- Send
X-Content-Type-Options: nosniff
header. - Send
X-Frame-Options: deny
header. - Send
Content-Security-Policy: default-src 'none'
header. - Remove fingerprinting headers -
X-Powered-By
,Server
,X-AspNet-Version
, etc. - Force
content-type
for your response. If you returnapplication/json
, then yourcontent-type
response isapplication/json
. - Don't return sensitive data like
credentials
,Passwords
, orsecurity tokens
. - Return the proper status code according to the operation completed. (e.g.
200 OK
,400 Bad Request
,401 Unauthorized
,405 Method Not Allowed
, etc.).
CI & CD
- Audit your design and implementation with unit/integration tests coverage.
- Use a code review process and disregard self-approval.
- Ensure that all components of your services are statically scanned by AV software before pushing to production, including vendor libraries and other dependencies.
- Design a rollback solution for deployments.
API Security Checklist Info
Modern web applications depend heavily on third-party APIs to extend their own services. However, an Akana survey showed that over 65% of security practitioners don’t have processes in place to ensure secure API access. With insecure APIs affecting millions of users at a time, there’s never been a greater need for security. Templarbit looks at the current best practices for building secure APIs.
Authentication
Authentication ensures that your users are who they say they are. Hackers that exploit authentication vulnerabilities can impersonate other users and access sensitive data.
Drop Basic Authentication
Basic Authentication is the simplest form of HTTP authentication. With each request, users submit their credentials as plain and potentially unencrypted HTTP fields. Instead, use a more secure method such as JWT or OAuth.
Don’t ship a home grown solution
Never try to implement your own authentication, token generation, or password storage methods. Depending on your application’s language or framework, chances are there are existing solutions with proven security. Review the language or framework documentation to learn how to implement these solutions.
Implement Max Retry and Jail safety mechanisms
Attackers will try to authenticate using a variety of credential combinations. Setting a maximum number of retries blocks users who fail too many authentication attempts in a certain amount of time. Users who exceed the number of max retries are placed in a “jail” which prevents further login attempts from their IP address until a certain amount of time passes.
Encrypt Everything
Always encrypt data before transmission and at rest. Intercepting and reading plain HTTP is trivial for an attacker located anywhere between you and your users. Encryption makes it exponentially harder for credentials and other important information to be compromised.
Access
Attackers don’t need to be authenticated in order to cause havoc.
Limit Requests
One of the most common attacks on the Internet is a Denial of Service (DoS) attack, which involves sending a large number of requests to a server. The server tries to respond to each request and eventually runs out of resources. Rate limit requests to mitigate DoS attacks by throttling or blocking IP addresses and work with vendors that are able to block DoS attacks before they can even reach your servers.
Force Encryption
Using unencrypted HTTP makes your users vulnerable to Man-In-The-Middle (MITM) attacks, which allows a hacker or third party to intercept sensitive data like usernames and passwords. Secure HTTP (HTTPS) encrypts data between clients and servers, preventing bad actors from reading this data.
Input
Just because users can log into your API doesn’t mean they can be trusted. Failing to validate user input is the cause of some of the web’s most debilitating vulnerabilities including Cross-Site Scripting (XSS) and SQL injections.
Enforce HTTP Methods
Each of your API’s endpoints should have a list of valid HTTP methods such as GET, POST, PUT, and DELETE. These methods should correlate to the action the user is attempting to perform (for example, GET should always return a resource, and DELETE should always delete a resource). Any operations that don’t match those methods should return 405 Method Not Allowed. This prevents users from accidentally (or intentionally) performing the wrong action by using the wrong method.
Perform Content Negotiation
When sharing data between the client and server, validate the type of content being sent. For example, if you expect the client to send JSON, only accept requests where the Content-Type header is set to application/json. If the content type isn’t expected or supported, respond with 406 Not Acceptable.
Validate User-Submitted Content
Malformed user input is the cause of some the most common vulnerabilities on the web, including:
- SQL Injection: A user submits a malicious database query as input. If the application passes input directly to a database, the database will run the query.
- Remote Code Execution: A user submits a command as input. If the application passes input directly to a shell or external application, the server will run the command.
- Cross-Site Scripting (XSS): A user submits JavaScript as input. If a browser renders the field containing this JavaScript, the browser will execute the code.
You can mitigate these attacks by scrubbing user input of HTML tags, JavaScript tags, and SQL statements before processing it on the server. Templarbit can help you getting started with Content-Security-Policy that can protect you from Cross-Site Scripting (XSS) attacks.
Components with Vulnerabilities
Remove unused dependencies, unnecessary features, components, files, and documentation. Continuously check the versions of your dependencies for known security flaws. Github provides this feature now out of the box for some repos. Besides removing and updating dependencies with known vulnerabilites you should also consider to monitor for libraries and components that are unmaintained or do not create security patches for older versions.
Check for trusted sources
When picking new dependencies only add code from official sources over secure links. Signed packages are ideal and reduce the chance of including a modified, malicious component into your application.
Data Processing
Scrubbing input won’t always prevent you from attacks. Specially crafted payloads can still execute code on the server or even trigger a DoS.
Protect Sensitive Endpoints
Make sure that all endpoints with access to sensitive data require authentication. This prevents unauthenticated users from accessing secure areas of the application and perform actions as anonymous users.
Avoid Using Auto-Incrementing IDs
Auto-incrementing IDs make it trivial for attackers to guess the URL of resources they may not have access to. Instead, use universally unique identifiers (UUID) to identify resources.
Process Data in the Background
Processing large amounts of data can prevent your API from responding in a timely manner. Instead of forcing the client to wait, consider processing the data asynchronously.
Turn Debug Mode Off
While it may seem obvious, make sure your application is set to production mode before deployment. Running a debug API in production could result in performance issues, unintended operations such as test endpoints and backdoors, and expose data sensitive to your organization or development team.
Logging & Monitoring
Ensure all login, access control failures, and server-side input validation failures can be logged with sufficient user context to identify suspicious or malicious accounts, and held for sufficient time to allow delayed forensic analysis. Logs that are generated should be in a format that can be easily consumed by a centralized log management solution.
Conclusion
There is no silver bullet when it comes to web application security. At Templarbit we understand the pain points of securing web applications. Our goal is to help web application developers understand security concepts and best practices, as well as integrate with the best security tools in order to protect their software from malicious activity.