Search This Blog

Showing posts with label Technical Skills. Show all posts
Showing posts with label Technical Skills. Show all posts

Monday, August 3, 2020

Top 10 Web Application Security Risks

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.

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. JWTOAuth).
  •  Don't reinvent the wheel in Authenticationtoken generationpassword 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 or RS256).
  •  Make token expiration (TTLRTTL) 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), and DELETE (to delete a record), and respond with 405 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/xmlapplication/json, etc.) and respond with 406 Not Acceptable response if not matched.
  •  Validate content-type of posted data as you accept (e.g. application/x-www-form-urlencodedmultipart/form-dataapplication/json, etc.).
  •  Validate user input to avoid common vulnerabilities (e.g. XSSSQL-InjectionRemote Code Execution, etc.).
  •  Don't use any sensitive data (credentialsPasswordssecurity tokens, or API keys) in the URL, but use standard Authorization header.
  •  Use an API Gateway service to enable caching, Rate Limit policies (e.g. QuotaSpike Arrest, or Concurrent 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-ByServerX-AspNet-Version, etc.
  •  Force content-type for your response. If you return application/json, then your content-type response is application/json.
  •  Don't return sensitive data like credentialsPasswords, or security tokens.
  •  Return the proper status code according to the operation completed. (e.g. 200 OK400 Bad Request401 Unauthorized405 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.

Tuesday, March 26, 2019

Git Cheat Sheet – Git Commands Testers Should Know

This post is a Git Cheat Sheet with the most common Git commands you will likely use on a daily basis.
If you are a technical tester working alongside developers, you should be familiar with the basic Git commands.
This post contains enough Git knowledge to get you going on a day to day basis as a QA.

Initial Git Setup

Initialize a repo

Create an empty git repo or re-initialize an existing one
$ git init

Clone a repo

Clone the foo repo into a new directory called foo:
$ git clone https://github.com//foo.git foo

Git Branch

How to Create a New Branch in Git

When you want to work on a new feature, you typically create a new branch in Git. As such, you generally want to stay off the master branch and work on your own feature branches so that master is always clean and you can create new branches from it.
To create a new branch use:
$ git checkout -b 

How to List Branches in Git

If you want to know what branches are available in your working directory, then use:
$ git branch
Example output
develop
my_feature
master

How to Switch Branches in Git

When you create a new branch then Git automatically switches to the new branch.
If you have multiple branches, then you can easily switch between branches with git checkout:
$ git checkout master
$ git checkout develop
$ git checkout my_feature

How to Delete Branches in Git

To delete a local branch:
$ git branch -d 
Use the -D option flag to force it.
To delete a remote branch on origin:
$ git push origin :

Git Staging

To stage a file is simply to prepare it for a commit. When you add or modify some files, you need to stage those changes into “the staging area.” Think of staging as a box where you put things in before shoving it under your bed, where your bed is a repository of boxes you’ve previously have shoved in.

Git Stage Files

To stage or simply add files, you need to use git add command. You can stage individual files:
$ git add foo.js
or all files at once:
$ git add .

Git Unstage Changes

If you want to remove a certain file from the stage:
$ git reset HEAD foo.js
Or remove all staged files:
$ git reset HEAD .
You can also create an alias for a command and then use it with Git:
$ git config --global alias.unstage 'reset HEAD'
$ git unstage .

Git Status

If you want to see what files have been created, modified or deleted, Git status will show you a report.
$ git status

Git Commits

It is a good practice to commit often. You can always squash down your commits before a push. Before you commit your changes, you need to stage them.
The commit command requires a -m option which specifies the commit message.
You can commit your changes like:
$ git commit -m "Updated README"

Undoing Commits

The following command will undo your most recent commit and put those changes back into staging, so you don’t lose any work:
$ git reset --soft HEAD~1
To completely delete the commit and throw away any changes use:
$ git reset --hard HEAD~1

Squashing Commits

Let’s say you have 4 commits, but you haven’t pushed anything yet and you want to put everything into one commit, then you can use:
$ git rebase -i HEAD~4
The HEAD~4 refers to the last four commits.
The -i option opens an interactive text file.
You’ll see the word “pick” to the left of each commit. Leave the one at the top alone and replace all the others with “s” for squash, save and close the file.
Then another interactive window opens where you can update your commit messages into one new commit message.

Git Push

After you have committed your changes, next is to push to a remote repository.

First Push

Push a local branch for the first time:
$ git push --set-upstream origin 
After that, then you can just use
$ git push

Push local branch to different remote branch

To push a local branch to a different remote branch, you can use:
$ git push origin :

Undo Last Push

If you have to undo your last push, you can use:
$ git reset --hard HEAD~1 && git push -f origin master

Git Fetch

When you use git fetch, Git doesn’t merge other commits them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files.
To integrate the commits into your master branch, you use merge.

Fetch changes from upstream:

$ git fetch upstream

Git Pull

Pulling is just doing a fetch followed by a merge. When you use git pull, Git automatically merges other commits without letting you review them first. If you don’t closely manage your branches, you may run into frequent conflicts.

Pull a branch

If you have a branch called my_feature and you want to pull that branch, you can use:
$ git pull origin/my_feature

Pull everything

Or, if you want to pull everything and all other branches
$ git pull

Git Merging and Rebasing

When you run git merge, your HEAD branch will generate a new commit, preserving the ancestry of each commit history.
The rebase re-writes the changes of one branch onto another without creating a new commit.

Merge Master Branch to Feature Branch

$ git checkout my_feature
$ git merge master
Or with rebase option, you use:
$ git checkout my_feature
$ git rebase master

Merge Feature Branch to Master Branch

$ git checkout master
$ git merge my_feature

Git Stash

Sometimes you make changes on a branch, and you want to switch to another branch, but you don’t want to lose your changes.
You can stash your changes. Here’s how you do a stash in Git:
$ git stash
Now, if you want to unstash those changes and bring them back into your working directory use:
$ git stash pop

My Profile

My photo
can be reached at 09916017317