Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:25:10+00:00 2026-06-11T14:25:10+00:00

I’m actually developing a Single Page App for my company that involves different views

  • 0

I’m actually developing a Single Page App for my company that involves different views for different user roles, to prevent people with not enough privileges to access data they are not supposed to see or to execute functions they don’t have the rights to do.

I’m using PHP with a REST api on the backend so I think I’m fairly safe there but I don’t know nothing about client-side security.

I was thinking about storing an App variable with the current user role like this way in my main.js:

require(['jquery',
    'underscore',
    'backbone',
    'marionette',
    'app',
    'routers/adminRouter',
    'routers/userRouter',
    ], function($, _, Backbone, Marionette, App, AdminRouter, UserRouter){

App.vent.on("routing:started", function(){
    Backbone.history.start();
});

App.addInitializer(function(){
    if(userRole==="admin"){
        App.Router = new AdminRouter;
    } else {
        App.Router = new UserRouter;
    }
    App.vent.trigger("routing:started");
});

App.addRegions({
   content: "#main",
   page: "#page",
   dialogs: "#dialogs"
});

App.start();

App.vars = {};

App.vars.userRole = userRole;

Where App.js is just:

define([
   'underscore',
   'backbone',
   'marionette'
   ], function(_, Backbone){

       var App = new Backbone.Marionette.Application();
       return App;
});

Variable userRole is just a global variable that I bootstrap from my server on index.php page. How much is this safe? There is a way to change userRole value on page load? Or to change App.vars.userRole while the App is going? I can’t access App variable from console but as I said I’m very new to the client-side programming and I must know if I can rely on that variable’s value. What’s the best way to approach a situation like this? Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:25:11+00:00Added an answer on June 11, 2026 at 2:25 pm

    What @devundef says is true. With security, all your authorization must happen on the server side. Once code is loaded client-side and in the wild, there is nothing preventing them from going through and changing it… in ways you don’t like. It might in some cases take a lot more effort (for example, if you minify stuff it’s harder to read) but it is definitely doable so stuff like that shouldn’t be relied on at all.

    As long as you’re checking server-side, it shouldn’t matter if a bad client does this. For example, you can have your userRole as a convenience variable that dictates how your client-side app behaves. They may maliciously change the userRole, give themselves a fake admin status, which gives them access to the admin View, but their play time ends when they want to do anything else (e.g. get data from the server, etc.) This is usually what it comes down to. Basically you want to protect actions (GET, POST, PUT, DELETE) that require certain authorization like admin status. Any sensitive route on your server has to have some check of this sort before it completes the request.

    Again, you can not trust when a client sends userRole = admin. What you do is you need to first, have authenticated that they are the user they claim to be, then second, authorize whether that user has appropriate privilege (like admin status). Each time.

    I use encrypted cookie sessions. After a user authenticates, they get the cookie which can’t be tampered with. So each time they make a request I use that cookie to say “Okay, this is indeed user X”. Once I have that I do a DB lookup to say “Okay, he is an admin”. If that checks out, I can fulfill the request. If not, I give them a rude error.

    In the case that perhaps, certain MODELS, VIEWS, and COLLECTIONS should not be accessible to people without certain privileges, I’m not sure what the best way to go about this would be. Usually the only thing I’m concerned about is the raw data in the DB. But, I might actually compile several different client-side applications (e.g. one for general users, one for only admins) and serve the appropriate one based on their status when they hit index. Well, to be honest I wouldn’t even make the initial request hit the same url. The procedure would still be the same though. 1) Authenticate and 2) Authorize.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.