{"id":17676344,"url":"https://github.com/stylet/js-acl","last_synced_at":"2025-06-26T13:34:25.988Z","repository":{"id":57282786,"uuid":"59815556","full_name":"StyleT/js-acl","owner":"StyleT","description":"Provides a lightweight and flexible ACL implementation for privileges management in JS/NodeJS","archived":false,"fork":false,"pushed_at":"2019-07-15T09:48:17.000Z","size":42,"stargazers_count":8,"open_issues_count":2,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T20:52:11.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StyleT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-27T07:45:06.000Z","updated_at":"2024-02-29T08:30:53.000Z","dependencies_parsed_at":"2022-08-31T00:31:19.645Z","dependency_job_id":null,"html_url":"https://github.com/StyleT/js-acl","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyleT%2Fjs-acl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyleT%2Fjs-acl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyleT%2Fjs-acl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StyleT%2Fjs-acl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StyleT","download_url":"https://codeload.github.com/StyleT/js-acl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253824248,"owners_count":21969986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-24T07:25:18.392Z","updated_at":"2025-05-12T21:25:47.293Z","avatar_url":"https://github.com/StyleT.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JS ACL\n\n[![Build Status](https://travis-ci.org/StyleT/js-acl.svg?branch=master)](https://travis-ci.org/StyleT/js-acl)\n[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/StyleT/js-acl/blob/master/LICENSE)\n\n---\n\n## About\nJS ACL _(Access Control List)_ is a service that allows you to protect/show content based on the current user's assigned role(s),\nand those role(s) permissions (abilities).\n\nFor the purposes of this documentation:\n- a **resource** is an object to which access is controlled.\n- a **role** is an object that may request access to a Resource.\n\nPut simply, **roles request access to resources**. For example, if a parking attendant requests access to a car,\nthen the parking attendant is the requesting role, and the car is the resource, since access to the car may not be granted to everyone.\n\nThrough the specification and use of an ACL, an application may control how roles are granted access to resources.\n\n## Quick Examples\n\nFirst you need to install this library :)\n\n- `npm install --save js-acl`\n\n```html\n\u003cscript src=\"/node_modules/js-acl/dist/acl.js\"\u003e\u003c/script\u003e\n```\n```js\nconst Acl = require('js-acl');\n```\n\n#### Set Data\n```js\n//In case of Node.js\nconst AclService = require('js-acl');\n//In case of Browser\nvar AclService = window.JsAcl;\n\n//All these actions you also can do in the middle of app execution\nAclService.addRole('guest');\nAclService.addRole('user', 'guest');\nAclService.addRole('admin', 'user');\n\nAclService.addResource('Post');\nAclService.addResource('Users');\nAclService.addResource('AdminPanel');\n\nAclService.allow('guest', 'Post', 'view');\n\n//Users can edit edit their own posts \u0026 view it because user inherits all guest permissions\nAclService.allow('user', 'Post', 'edit', function (role, resource, privilege) {\n    return resource.authorId === role.id;\n});\n\n//Full access to all actions that available for Post\nAclService.allow('admin', 'Post');\nAclService.allow('admin', 'AdminPanel');\n\n//Let's assume that you have some user object that implements AclRoleInterface. This is optional feature.\nvar user = {\n    id: 1,\n    name: 'Duck',\n    getRoles: function () {\n        return ['user'];\n    },\n};\nAclService.setUserIdentity(user);\n```\n\n\n## How secure is this if I'm using it in browser?\n\nA great analogy to ACL's in JavaScript would be form validation in JavaScript.  Just like form validation, ACL's in the\nbrowser can be tampered with. However, just like form validation, ACL's are really useful and provide a better experience\nfor the user and the developer. Just remember, **any sensitive data or actions should require a server (or similar) as the final authority**.\n\n#### Example Tampering Scenario\n\nThe current user has a role of \"guest\".  A guest is not able to \"create_users\". However, this sneaky guest is clever\nenough to tamper with the system and give themselves that privilege. So, now that guest is at the \"Create Users\" page,\nand submits the form. The form data is sent the the server and the user is greeted with an \"Access Denied: Unauthorized\"\nmessage, because the server also checked to make sure that the user had the correct permissions.\n\nAny sensitive data or actions should integrate a server check.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstylet%2Fjs-acl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstylet%2Fjs-acl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstylet%2Fjs-acl/lists"}