< Go Back

Understanding Sources and Sinks: A Guide to Taint Analysis

What is source and sinks? identify untrusted data flow in various frameworks and languages.

   During testing or code reviews, it’s crucial to understand how users input flows through a system. The ability to read the code of the application and understand it thoroughly is just as important as breaking that application.

     This understanding enables us to spot weaknesses and safeguard the system more effectively. One powerful technique to achieve this is taint analysis. In that spirit, let’s delve into the concepts of sources and sinks.


Understanding Taint Analysis

   Taint analysis is a method used to track the flow of data through a program, start to end. It helps in identifying how data from an untrusted source can affect the execution of a program, potentially leading to security breaches.

The Role of Sources and Sinks

In taint analysis, the concepts of sources and sinks are fundamental:


/sourceandsink

Why Taint Analysis is Important

   When we test systems or do code reviews, we don’t always have the luxury of a UI to observe how data flows. In such a scenario taint analysis is apt. It allows us to trace the path of user inputs through the system, highlighting how they interact with different components and where they ultimately end up.

     This visibility is critical in identifying potential vulnerabilities, such as SQL injection points, cross-site scripting (XSS) vulnerabilities, and other forms of data mishandling.


Finding Sources and Sinks in Different Languages and Frameworks

    The methods for identifying sources and sinks can vary depending on the programming language and framework being used. Here’s a guide on how to approach this in some common scenarios:

JavaScript and Web Development sources

  JavaScript sources include various properties and methods that can accept user input:


TypeScript and React sources


DOM-XSS sinks

These are some sinks that can lead to DOM-based XSS vulnerabilities:


JavaScript Injection sinks

Potentially dangerous functions that can execute JavaScript code:


Open-Redirection sinks

These properties can lead to open redirection vulnerabilities:


Python and Django/Flask

Common Sources

Sinks


Java and Spring

Common Sources

Sinks


C# and ASP.NET

Common Sources

Sinks


Steps to Implement Taint Analysis

   1] Identify Sources: Begin by mapping out where user inputs enter your system. This could be through form fields, API endpoints, or other interfaces.

   2] Trace the Flow: Follow the data as it moves through your system. Look for functions and methods that process or manipulate this data.

   3] Identify Sinks: Determine where the data ends up, whether it’s being stored, displayed, or used in critical operations.

   4] Analyze and Mitigate: Look for patterns where data might be mishandled. Ensure that all data reaching sinks is properly validated and sanitized to prevent vulnerabilities.


Tools to Aid

  There are various tools available to help identify sources and sinks.

PortSwigger Labs

  PortSwigger offers practical labs where one can practice identifying sources and sinks: PortSwigger Labs

Semgrep

   Semgrep is a powerful tool for rule-based scanning. It allows you to create custom rules to identify sources and sinks in your code. Read more about how Semgrep can be used: Semgrep Documentation

Burp Canary

  Burp Canary, an extension in BurpSuite that’s pre-installed in Burp’s browser. This enhances sources and sinks analysis by injecting unique tokens (“canaries”) into the requests and tracks their flow. This precise tracking highlights how user input (sources) moves through the system to critical endpoints (sinks), identifying potential vulnerabilities. This automation complements taint analysis. Read more at: Burp Canary

BurpSuite BCheck Scripts

  For scenarios where a UI is available, you can develop a BCheck script in Burp Suite to automate the identification of sources and sinks while you casually browse the application. Here is an example script for JavaScript sinks:

BCheck Script bash
metadata: language: v2-beta name: "JS sinks for DOM-XSS (passive)" description: "JavaScript sink that could lead to DOM-XSS." author: "Kaustubh" tags: "passive" given response then if {latest.response} matches "document.write|document.writeln|document.domain|\.innerHTML|\.outerHTML|\.insertAdjacentHTML|\.onevent" then report issue and continue: severity: info confidence: firm detail: "JavaScript sink that could lead to DOM-XSS." remediation: "Investigate if this sink can be used to do a DOM-XSS." end if

Checkout more Bcheck scripts here


Conclusion

   Understanding sources and sinks is crucial in identifying potential vulnerabilities in a system. By recognising where untrusted data enters (sources) and where it is executed or stored (sinks), can safeguard against attacks.

^ Back to Top