Search This Blog

Monday, August 3, 2020

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.

Thursday, October 17, 2019

Framework Evaluation & Selection

Framework Evaluation Criteria

  1. Support automation integration testing for UI (real/headless browser/device), API,  performance in cross platforms.

    • For the integration test, we don’t test the front-end or back-end individually. We need to verify the data with the integration between system, front-end & back-end. So the framework needs to be able to support all testing type and especially crossing browser, device & system.
  2. Support CI integration with parallel execution.

    • The testing framework needs to be able to integrate with our current CI/CD. Parallel execution will help reduce the build time, so we will be able to deploy quickly and have faster turnaround times for bugs and features.
  3. Supports the concept of executable documentation for BDD (behavior-driven development)& DDT (data-driven testing) in modularization, maintainable and understandable test suites.

    • BDD will help the test case & test suite easy to maintaining and understanding. It also helps communication between business and development is extremely focused as a result of common language.
    • One of the most important concepts for effective test automation is modularization, it will help to create a sequence of test case only one and reuse as often as required in test script without rewriting the test all the time.

BDD Testing Framework Selection


GaugeCucumber
LanguageMarkdownGherkin
IDE & plugin supportYesYes
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnNoNo
Reusable, easy to maintainYesYes
Parallel executionBuilt-in3rd party plugin
Customize reportingYesYes
PriceOpen source & free Open source & free 

Winner - Gauge:

  • An open source lightweight cross-platform test automation tool with the ability to author test cases in the business language and have built-in parallel execution feature.
  • Support BDD (Behavior-Driven Development) & CI(Continuous Integration) & report customization.

API Testing Framework Selection


REST AssuredPostman
Support BDDYes3rd third party
Support DDTYesLimit
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnNoYes
Reusable, easy to maintainYesNo
Customize reportingCan be used with any customized/open source reporting tool.No
PriceOpen source & free 8-21$ per user/month for professional collaboration  & advanced features
  

Winner - REST Assured:

  • An open source Java-based Domain-Specific Language (DSL) that allows writing powerful, readable, and maintainable automated tests for RESTful APIs. 
  • Support testing and validating REST services in BDD (Behavior-Driven Development) / Gherkin format.

API Performance Testing Framework  Selection


Apache JMeterLoadrunner
Support DDTYesYes
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnYesNo
Cross-platformYesWindows, Linux
Reusable, easy to maintainYesNo
Customize reportingYesYes
PriceOpen source & free Free for first 50 virtual User

Winner - Apache JMeter : 

  • Open source performance test runner & management framework may be used to test performance both on static and dynamic resources.
  • Support load test functional behavior and measure performance. It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types.

Test Runner & Test Suite Management Framework Selection


TestNGJUnit
Support DDTYesYes
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnNoNo
Reusable, easy to maintainYesYes
Parallel executionYesYes
PriceOpen source & free Open source & free 
Annotation supportYesLimit
Suite TestYesYes
Ignore TestYesYes
Exception TestYesYes
TimeoutYesYes
Parameterized TestYesYes
Dependency TestYesNo
Support executing before & after all tests in the suiteYesNo
Support executing  before & after a test runsYesNo
Support executing  before the first & last test method
is invoked that belongs to any of these groups is invoked
YesNo

Winner - TestNG :

  • Open source test runner framework which helps to run your tests in arbitrarily big thread pools with various policies available and flexible test configuration.
  • Support DDT(Data-driven testing) & Test suite management.

Build Tool & Dependency ManagementFramework Selection


Apache MavenGrandle
Easy to integrate with CI/CDYesYes
Easy to use, quick to learnYesNo
Build Script LanguageXMLGroovy
Reusable, easy to maintainYesYes
Dependency ManagementYesYes
Dependency ScopesBuilt-inCustom
IDE & plugin supportManyA little
PriceOpen source & free Open source & free 

Winner - Apache Maven 

  • The leading open source dependency management and build tool. It standardizes the software build process by articulating a project’s constitution.
  • Software project management and comprehension tool in the concept of a project object model (POM), Maven can manage a project's build, reporting, and documentation from a central piece of information.

My Profile

My photo
can be reached at 09916017317