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.
sequelize-strict-attributes
Advanced tools
Plugin that configures Sequelize to throw when accessing attributes omitted from a select.
sequelize-strict-attributes
is a plugin for Sequelize that adds stricter treatment of attribute access after specifying attributes in a query. This way, attempts to access instance attributes omitted from the query using attributes
will throw rather than silently failing by returning undefined. This is especially useful for scenarios where the column is expected to sometimes be null so a fallback value is provided for calculations.
Note: this is a runtime check. Types are included for the plugin itself, but the types of the returned instances will not be changed. To type checking, the instances will appear to still have omitted attributes.
npm install sequelize-strict-attributes
and include as a JavaScript or TypeScript module (types included):
import sequelizeStrictAttributes from 'sequelize-strict-attributes';
…or a CommonJS module:
const sequelizeStrictAttributes = require('sequelize-strict-attributes');
Supports the latest stable Sequelize, version 6.
Call the plugin with the active Sequelize instance immediately after it's instantiated.
const sequelize = new Sequelize(…);
sequelizeStrictAttributes(sequelize);
From this point on, any Model.findAll
or Model.findOne
query that specifies attributes:
—and does not use raw: true
—will throw if you try to access an attribute not included in the select list.
For example, given a model that looks something like this:
const Cart = sequelize.define("Cart", {
subtotal: DataTypes.STRING,
tax: DataTypes.INTEGER,
});
And an instance fetched like this:
const cart = await Cart.findOne({
attributes: ["subtotal"],
});
When accessing the omitted attribute to determine if tax
needs to be calculated, the program will throw:
if (cart.tax === null) { // <-- Throws!
cart.tax = cart.subtotal * TAX_RATE;
}
if (cart.get("tax") === null) { // <-- Also throws
Included models will similarly be restricted if their attributes are specified on the include
.
const cart = await Cart.findOne({
attributes: [],
include: {
model: Customer,
attributes: ["name"],
},
});
await sendReceiptEmail({
name: cart.Customer.name,
email: cart.Customer.email, // <-- Throws here!
});
Setting the attribute directly or using Model::set
will still work. These changes can be saved as expected, though you won't be able to read them back on the same instance, even after a .reload()
. (Though shortcuts like addition–assignment will naturally throw.)
Disallowing access of attributes that were excluded from a select is a common feature of other ORMs for good reason (eg Prisma excludes it from the returned type, ActiveRecord and Django throw errors on access). However, the Sequelize authors declined to support it in the core library. In lieu of core support, this plugin will help guard against the hazard.
This package is licensed under the MIT License.
See ./LICENSE
for more information.
FAQs
Plugin that configures Sequelize to throw when accessing attributes omitted from a select.
The npm package sequelize-strict-attributes receives a total of 102 weekly downloads. As such, sequelize-strict-attributes popularity was classified as not popular.
We found that sequelize-strict-attributes 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.