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 7034025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:08:10+00:00 2026-05-28T01:08:10+00:00

I have a Note domain object which belongs to a Document object. Only an

  • 0

I have a Note domain object which belongs to a Document object. Only an owner of a Document can add Notes so in the Document class there is a canUserAccess() method. In my service layer I can call canUserAccess() to ensure a user only adds Notes to Documents they own.

This works well for create but I have hit a problem with my Note edit action. On post, the viewmodel is mapped to a Note object, providing it with a DocumentID. Problem is, a malicious user could send in a DocumentID on which they do have permission and thus edit a Note belonging to a Document they don’t. In my service layer I cannot reliably use the supplied DocumentID yet I need to get the related DocumentID in order to verify that the user can edit the Note. This is an example:

public void editNote(Note note)
    {
        note.Document = documentRepository.Find(note.DocumentID);

        if(note.Document.canUserAccess())
    }

How do I get around this? It seems I need to avoid passing the DocumentID with the edit viewmodel but how do I hydrate the related Document in the service layer? There is probably a really simple solution to this and I am just tying myself up in circles!

  • 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-05-28T01:08:11+00:00Added an answer on May 28, 2026 at 1:08 am

    You do this with BindAtrribute for the model or for the action method by adding a white list with the properties you want to be bound :

    for the model

    [Bind(Include="NoteText,NoteTitle")] 
    public Model{}
    

    for the action method

    public ViewResult Edit([Bind(Include="NoteText,NoteTitle"]Note note)){}
    

    or use a black list for the properties you don’t want to bind :

    [Bind(Exclude="DocumentID")] 
    public Model{}
    

    I would personally use white list with the model class. You might find this article interesting. The last section for under-posting is your case.

    Then you don’t have the documentID passed, but in your action you can do this:

    public ViewResult Edit(Note note)
    {
      Note updateNote = nodesRep.Get(note.noteID);
    
      if(updateNote.Document.canUserAccess())
      {
          //replace the values of the updateNote
          //you can place this line in your base Repository class 
          context.Entry<Note>(updateNote).CurrentValues.SetValues(note); //I assume EF 4.1
      }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a domain object that looks like this: class Note { Long
I have a property on my domain object which is exposed as this: public
I have to give a general note to some huge Java project for which
I have a domain class like this: public class DomainClass { public virtual string
I have a Domain object called User and UserCreateViewModel.Automapper is used for mapping from
I have an iPhone application in which a number of domain objects are populated
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
NOTE: I have solved the majority of this problem but have run into a
Note: I have given up on compiling iPhone Apps without a developer certificate for
Note I have completely re-written my original post to better explain the issue I

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.