Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nt-fingerprint

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nt-fingerprint

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

nt-fingerprint

test

Synopsis

nt-fingerprint is a Ruby gem for converting queries into fingerprints.

require 'nt/fingerprint'

class Sample
  include Nt::Fingerprint
end

puts Sample.new.fingerprint("SELECT a, b, 'c' FROM t WEHERE a = 1 AND b IN (1, 2, 3)")
# => select a, b, ? from t wehere a = ? and b in(?+)

nt-fingerprint exposes a single method fingerprint. What the method does is just calling a function query.Fingerprint of percona/go-mysql via FFI. Thus, the behavior of fingerprint completely follows that of query.Fingerprint. We quote the description of query.Fingerprint from the documentation of go-mysql.

func Fingerprint(q string) string

Fingerprint returns the canonical form of q. The primary transformations are:

- Replace values with ?
- Collapse whitespace
- Remove comments
- Lowercase everything

Additional trasnformations are performed which change the syntax of the original query without affecting its performance characteristics. For example, "ORDER BY col ASC" is the same as "ORDER BY col", so "ASC" in the fingerprint is removed.

Examples

A typical use case of nt-fingerprint is query logging. Using nt-fingerprint, one can exclude sensitive information from queries. This makes it possible to log production queries while maintaining security.

For example, one can capture arbitrary ActiveRecord queries by combining Arproxy and nt-fingerprint.

class QueryLogger < Arproxy::Base
  include Nt::Fingerprint

  def execute(sql, name=nil)
    Rails.logger.info(fingerprint(sql))
    super(sql, name)
  end
end

Arproxy.configure do |config|
  config.use QueryLogger
end

FAQs

Package last updated on 12 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc