Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
= QueryBuilder
== DESCRIPTION:
QueryBuilder is an interpreter for the "pseudo sql" language. This language can be used for two purposes:
QueryBuilder is just a parser that produces as AST tree and a default Processor to help you apply scopes, change classes, insert joins, etc. Compared to things like arel, QueryBuilder lets you build your own expressive language and let your end users safely play with it.
Small comparison between native Rails, Arel and Pseudo SQL to display the portraits of the current user's friends:
Rails:
Images.find(:all, :joins => "INNER JOIN people ON images.id = people.portrait_id INNER JOIN friends ON friends.target_id = people.id", :conditions => ["friends.source_id = ?", visitor.id])
Arel:
Table(:images).join(people).on(images[:id].eq(people[:portrait_id])).join(friends).on(friends[:target_id].eq(people[:id])).where(friends[:source_id].eq(visitor.id))
Pseudo SQL:
portraits from friends
I am sure that I made not mistake in the 3 words of my pseudo-sql query (which just says what I think). The other two completely leak the underlying implementation and I could have made tons of syntax errors or security breaches...
== PSEUDO SQL Syntax
Everything in brackets is optional:
'RELATION [where CLAUSE] [select CLAUSE] [in SCOPE] [from SUB_QUERY] [group by GROUP_CLAUSE] [having HAVING_CLAUSE] [order by ORDER_CLAUSE] [limit num(,num)] [offset num] [paginate key]'
The where CLAUSE can contain the following operators (lt, gt, le, etc are the same as '<' and company but avoid escaping in xml/html environments):
'+' | '-' | '<' | '<=' | '=' | '>=' | '>' | '<>' 'or' | 'and' | 'lt' | 'le' | 'eq' | 'ne' | 'ge' | 'gt' 'like' | 'not like' | 'match' | 'in'
This lets you build complex queries like:
images where tag = 'nature' and event_at.year = #{now.year - 1} in project from favorite_projects paginate p
In the compiler, 'images' could be resolved as a filter on class type (filter_relation), "tag = 'nature'" as a special case in process_equal, 'year' will be resolved depending on the SQL connection to something like strftime('%Y', event_at), 'project' as a scope and 'favorite_projects' as a join_relation.
You can also use 'functions' such as event_at.year or event_at.coalesce(0).
This might seem very complex, but usually, you start with a basic compiler and augment it when needs arise to build more powerful queries.
A last note: if you insert #{something} (ruby dynamic string), it will be used as a bound variable evaluated using RubyLess. This is perfectly safe:
images where name like '#{params[:img]}%' in site limit 5
And will be resolved as something like this:
Image.find_by_sql([%Q{SELECT images.* WHERE name LIKE ? LIMIT 5}%, "#{params[:img]}%"])
== SYNOPSIS:
query = DummyQuery.new("images where name like '%flower%' from favorites")
query.to_s => "['SELECT ... FROM ... WHERE links.source_id = ?', @node.id]"
query.sql(binding) => "SELECT ... FROM ... WHERE links.source_id = 1234"
query.to_s(:count) => "['SELECT COUNT(*) ... WHERE links.source_id = ?', @node.id]"
query.sql(binding, :count) => "SELECT COUNT(*) ... WHERE links.source_id = 1234"
== REQUIREMENTS:
== INSTALL:
sudo gem install querybuilder
== Creating your own builder
To process queries for your own classes, you need to create a sub class of QueryBuilder::Processor and overwrite processing methods (See QueryNode or QueryComment in Zena CMS project for an example).
Warning: when you write filters, if you join multiple clauses by hand with " AND " or " OR ", you have to enclose the group in parenthesis to avoid problems.
== LICENSE:
(The MIT License)
Copyright (c) 2008-2009 Gaspard Bucher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that querybuilder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.