Coder Social home page Coder Social logo

Comments (2)

xtrasmal avatar xtrasmal commented on September 21, 2024

Right now I'm doing this in the _Header.tpl.php:

<script type="text/javascript">
    var currUser = <?php $this->eprint( $this->currentUser->Id );?>;
</script>

and in my backbone model.js

/**
 * Post Backbone Model
 */
model.PostModel = Backbone.Model.extend({
    urlRoot: 'api/post',
    idAttribute: 'id',
    id: '',
    authorId: '',
    date: '',
    content: '',
    title: '',
    excerpt: '',
    commentCount: '',
    defaults: {
        'id': null,
        'authorId': currUser,
        'date': new Date(),
        'content': '',
        'title': '',
        'excerpt': '',
        'commentCount': ''
    }
});

after I assigned the getCurrentUser to the Init() of the AppBaseController.php

It works, but it feels like cheating.

from phreeze.

jasonhinkle avatar jasonhinkle commented on September 21, 2024

So, you're not exactly cheating but when it comes to anything involving authentication (like who the current user is) there's a a good mantra that you have to keep in mind. That is - never trust the client! (ie never trust any information that comes from the browser). It's perfectly ok to assign the user fields to the client. But, as long as that data is never used to obtain or change stuff on the server.

The good thing is - the server already knows who the current user is because they are logged in. So you don't even have to pass the current user ID to the server. In fact, you never should. Here's some code for example:

// don't do this...
$post->AuthorId = RequestUtil::Get('authorId'); // <- anybody can manipulate this - bad!

// do this instead...
$post->AuthorId = $this->GetCurrentUser()->Id;  // <- the user has no ability to manipulate this - good!

So, those kind of defaults should happen on the server side where the user can't manipulate it. Otherwise a malicious person could just observe how your application works and then mess with the calls and change the user id - thus emulating another user - which depending on what you are doing could be a security problem.

from phreeze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.