Class TaintQuery


  • public class TaintQuery
    extends Object
    A source-to-sink taint search over a code property graph, configured with source, sink, and sanitizer definitions.
    • Constructor Detail

      • TaintQuery

        public TaintQuery​(CodePropertyGraph cpg)
        Creates an empty query over a graph, defaulting to a 50 node path cap and interprocedural traversal.
        Parameters:
        cpg - the graph to search
    • Method Detail

      • getSinks

        public List<TaintSink> getSinks()
        Returns:
        the sinks
      • getMaxPathLength

        public int getMaxPathLength()
        Returns:
        the max path length
      • isInterprocedural

        public boolean isInterprocedural()
        Returns:
        whether interprocedural
      • addSource

        public TaintQuery addSource​(TaintSource source)
        Registers one source definition.
        Parameters:
        source - the source to match call sites against
        Returns:
        this query
      • addSources

        public TaintQuery addSources​(TaintSource... sources)
        Registers several source definitions.
        Parameters:
        sources - the sources to match call sites against
        Returns:
        this query
      • addSink

        public TaintQuery addSink​(TaintSink sink)
        Registers one sink definition.
        Parameters:
        sink - the sink to match call sites against
        Returns:
        this query
      • addSinks

        public TaintQuery addSinks​(TaintSink... sinks)
        Registers several sink definitions.
        Parameters:
        sinks - the sinks to match call sites against
        Returns:
        this query
      • addSanitizer

        public TaintQuery addSanitizer​(TaintQuery.Sanitizer sanitizer)
        Registers one sanitizer.
        Parameters:
        sanitizer - the sanitizer to match path hops against
        Returns:
        this query
      • addSanitizer

        public TaintQuery addSanitizer​(String ownerPattern,
                                       String methodPattern)
        Registers a sanitizer built from a pair of regexes.
        Parameters:
        ownerPattern - regex for the declaring class internal name
        methodPattern - regex for the method name
        Returns:
        this query
        Throws:
        PatternSyntaxException - if either pattern is not valid regex
      • maxPathLength

        public TaintQuery maxPathLength​(int length)
        Caps how many nodes a reported path may contain.
        Parameters:
        length - the maximum hop count
        Returns:
        this query
      • interprocedural

        public TaintQuery interprocedural​(boolean enabled)
        Controls whether traversal follows call, parameter, and return edges across methods.
        Parameters:
        enabled - true to cross method boundaries
        Returns:
        this query
      • withDefaultSources

        public TaintQuery withDefaultSources()
        Adds the built-in sources for HTTP input, console input, file reads, environment, and database reads.
        Returns:
        this query
      • withDefaultSinks

        public TaintQuery withDefaultSinks()
        Adds the built-in injection, traversal, SSRF, deserialization, and reflection sinks.
        Returns:
        this query
      • withDefaultSanitizers

        public TaintQuery withDefaultSanitizers()
        Adds the built-in sanitizers for URL encoding, OWASP and commons-text escaping, and prepared statements.
        Returns:
        this query
      • findSourceNodes

        public List<CPGNode> findSourceNodes()
        Scans every call site in the graph for one matching a registered source.
        Returns:
        the matching call site nodes
      • findSinkNodes

        public List<CPGNode> findSinkNodes()
        Scans every call site in the graph for one matching a registered sink.
        Returns:
        the matching call site nodes
      • analyze

        public TaintAnalysisResult analyze()
        Walks data flow edges from every source node to every reachable sink, capped at ten paths per pair.
        Returns:
        the collected paths, each already checked for sanitizers