Skip to content

Security Flaw with localStorage #112

@sarj21

Description

@sarj21

There is a major security issue with how the user data is stored and accessed.

First off, in Session.js when a new Session object is created the user is stored in local storage

    this.create = function(token, user){
      ...
      $window.localStorage.currentUser = JSON.stringify(user);
      ...
    };

This seems fine as they are themselves, however, in routes.js

     if (requireAdmin && !Session.getUser().admin) {
        return transition.router.stateService.target("app.dashboard");
      }

      if (requireVerified && !Session.getUser().verified) {
        return transition.router.stateService.target("app.dashboard");
      }

      if (requireAdmitted && !Session.getUser().status.admitted) {
        return transition.router.stateService.target("app.dashboard");
      }

We get from Session.getUser which just fetches the user from localStorage. So, if a user just opens the inspector and changes the localStorage object:

> localStorage.getItem("currentUser")
< // the currentUser object
> localStorage.setItem("currentUser", {...,'admin': true,...}) // copied from above

they can gain access to the admin tab

We actually had an attendee of our hackathon note this to us and we are mostly admins already so we didn't recreate exactly before changing this. Either way, I made a change that makes Session.getUser use the existing users/:id route in the api and I still store the user id in local storage, as that seems relatively harmless

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions