JavaScript: From Closures to Autonomous Systems

Chapter 16. Reactivity Under Access Control

Part IV. Distributed Reactivity6 min

16

Reactivity Under Access Control

For many years a new Meteor application was created with two packages that every tutorial told you to remove first. The autopublish package sent every client the whole database, and the insecure package let any client write anything into any collection. With them a prototype came together in an evening, because you did not have to think about either subscriptions or methods. Remove them, and the prototype stopped showing anything until the programmer wrote at least one publication. Today autopublish no longer goes into new projects by default. But in those years the platform, having taken on data delivery, left the programmer one main question, who has the right to see and change what, and itself answered it with «everyone, everything».

Once these packages were removed, read access control in Meteor came down to the publication function. We saw it in the fourteenth chapter:

Meteor.publish('orders', function () {
  if (Roles.userIsInRole(this.userId, 'manager')) {
    return Orders.find();
  }
  return Orders.find({ owner: this.userId });
});

Whatever this function returns is what ends up in the user’s Minimongo. Meteor offered no separate place describing who may do what. Roles were added with a third-party package, most often alanning:roles, which is where the Roles.userIsInRole call comes from. The idea of roles itself is old. In 1992 David Ferraiolo and Richard Kuhn of NIST described role-based access control: permissions are granted to roles, people are given roles, and to change the permissions of an employee moved to another department it is enough to change their role. In 2014 NIST published a guide to the next step, where the decision is made based on attributes of the user, the data and the environment. But these are all models, and in Meteor the access rule lived inside a function that returns a cursor, and was exactly as careful as the programmer who wrote it.

Free, one step away

The rest of the book is free

Leave your email and I will send a link to confirm it. Once you click it, every chapter opens here, on this device, for a year. When a new book comes out I will write to this address; reply “stop” to any email and I will not write again.

Have an INITE account? Sign in and the book opens without an email.

I do not charge for the book. If you would like to support it, you can donate from any chapter.

How your email is stored