
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Veryfay (TypeScript) is a library for doing activity based authorization in TypeScript.
It deals with three things:
When it comes to building a security system, probably the favoured approach is the so called role based security (RBA). The idea is fairly simple, users are assigned roles and in turn the roles have associated permissions (or activities).
While it appears like a good idea at first and it certainly works well if the number of roles is limited to just a few, it may get quickly very complicated when the number of roles increases.
An apparent drawback is that it becomes difficult to determine all the roles allowed (or denied) for a certain activity.
The alternative is called activity based authorization (ABA) and it is the role based security turned on its head, if you will. It solves the aforementioned drawback by making activity the central concept of the security mechanism.
Define authorization rules |
---|
RBA
role > activities
ABA
activity > roles
RBA works by associating activities to each role while ABA associates roles to each activity.
Verify authorization rules |
---|
RBA
input principal > roles > activities
&input activity
ABA
a.input activity > roles > principals
&input principal
b.input activity > roles
&input principal > roles
When checking for authorization, RBA starts from the specified principal, determines associated roles and intersects their activity sets with the input activity.
ABA mirrors that process, it starts from the specified activity, determines associated roles and intersects their principal sets with the input principal (case a shown above).
Case b shows the more practical approach, it starts from the specified activity and determines its associated roles then determines the roles associated to the input principal and intersects the two sets of roles.
npm install veryfay
The distribution directory should contain:
veryfay.js
and its minified version veryfay-min.js
veryfay.d.ts
and veryfay.node.d.ts
import * as Veryfay from "veryfay";
/// <reference path="./node_modules/veryfay/veryfay.d.ts" />
veryfay = require("veryfay");
This part consists of a few straightforward preparatory operations that culminate with the creation of an "authorization engine" to be used later to perform authorization verification.
An activity takes a class type parameter describing the target for the activity, which may be any class defined in your application.
For activities with no target, you should specify Nothing as the type argument of the activity.
There are a few predefined activities:
You may define your own activities by inheriting from Activity<TTarget>
:
class SomeActivity<TTarget> extends Veryfay.Activity<TTarget> {
constructor(target: Veryfay.Ctor<TTarget>) {
super(target);
}
}
Container activities help with associating multiple actions to the same role(s).
Instead of repeating the same activities over and over again, a container activity may be defined holding a list of activities (including container activities).
There a couple predefined container activities:
Define your own container activities like so:
export class SomeContainerActivity<TTarget>
extends Veryfay.Activity<TTarget>
implements Veryfay.Container<TTarget> {
private _activities: Veryfay.Activity<TTarget>[];
constructor(target: Veryfay.Ctor<TTarget>) {
super(target);
this._activities = [
new Veryfay.SomeActivity<TTarget>(this.target),
new Veryfay.SomeOtherActivity<TTarget>(this.target)];
}
activities() { return this._activities; }
}
Veryfay.Utils.applyMixins(SomeContainerActivity, [Veryfay.Container]);
Note: Container activities are used only for defining authorization rules, they are not used when verifying authorization rules
You may define a role by inheriting from Role<TPrincipal, TExtraInfo>
, where
In contains
you can place any logic to determine if the input data belongs to that role.
class SomeRole extends Veryfay.Role<SomePrincipalClass, SomeClass> {
private static _instance = new SomeRole(new SomePrincipalClass(), new SomeClass());
static get instance() { return SomeRole._instance; }
constructor(private _principal: SomePrincipalClass, private _extraInfo: SomeClass) {
super();
if (SomeRole._instance)
throw new Error("instantiation failed: use .instance instead of new");
SomeRole._instance = this;
}
principal() { return this._principal; }
extraInfo() { return this._extraInfo; }
contains(principal: SomePrincipalClass, extraInfo?: SomeClass): boolean {
// Some logic to determine if input belongs to the role
}
}
You may use register
, allow
, deny
and and
to associate any allow and deny roles with one or more activities in the context of an authorization engine:
let ae: Veryfay.AuthorizationEngine = new Veryfay.AuthorizationEngine()
.register(new Veryfay.CRUDP(Veryfay.Nothing))
.allow(Admin.instance).deny(Supervisor.instance, Commiter.instance).deny(Contributor.instance).and
.register(new Veryfay.CRUDP(SomeOtherClass))
.allow(Admin.instance).allow(Supervisor.instance).allow(Reader.instance).allow(Contributor.instance).and
.register(new Veryfay.Create(Veryfay.Nothing))
.allow(Commiter.instance).deny(Contributor.instance).and
.register(new Veryfay.Read(Veryfay.Nothing))
.allow(Commiter.instance).deny(Contributor.instance).allow(Reviewer.instance).and
.register(new Veryfay.Read(SomeClass))
.allow(Supervisor.instance, Commiter.instance).and
.register(new Veryfay.Read(SomeClass), new Veryfay.Read(SomeOtherClass))
.allow(Supervisor.instance).allow(Contributor.instance).deny(Reader.instance).and
.register(new Veryfay.Read(SomeClass))
.allow(Reader.instance).and
.register(new Veryfay.Read(OtherSomeOtherClass))
.allow(Reader.instance).deny(Commiter.instance).allow(Reviewer.instance).and;
Notes:
allow
or deny
are bound together by logical ANDallow
or deny
are bound together by logical ORTo verify the authorization rules you may call either:
isAllowing
which returns isAllowingResult
containing the result of the verification as a bool value and a string with information about the execution of the authorization ruleslet result = ae.get(new Veryfay.Read(SomeOtherClass)).isAllowing(new OtherPrincipalClass("reader"), [1234, "1234"]);
verify
which returns string
in case of success, otherwise throwing AuthorizationException
containing a string with information about the execution of the authorization rulesae.get(new Veryfay.Read(SomeOtherClass)).verify(new OtherPrincipalClass("reader"), [1234, "1234"]);
Note: During rules verification, role definitions are matched both by activity type and by the types of the arguments (for principal and optionally extra info) which are passed in to
isAllowing
orverify
FAQs
Activity based authorization library for TypeScript
The npm package veryfay receives a total of 3 weekly downloads. As such, veryfay popularity was classified as not popular.
We found that veryfay 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.