We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38538
    • 30 Posts
    Hi everyone,
    the website i'm developing has a certain number of reserved pages with a user group called "Publisher", connected with its respective access rules for context and resource group "Pannello Utente". I followed the classic guide http://rtfm.modx.com/display/revolution20/Making+Member-Only+Pages and everything worked fine...
    In this website, every member user can upload several pdf files, which have to be seen only by its owner (i've already set properly the PDF content type).

    At upload time, I use this code for creating a new user group associated with the current user, inserting user in the user group, creating resource group associated to the user group just created and setting its respective access rules for web context and resource group.

    $id = $modx->user->get('id');
        $name = $modx->user->get('username');
    
        $group = $modx->getObject('modUserGroup', array('name' => $name));
    
        if(!$group){
            $group = $modx->newObject('modUserGroup');
            $group->set('name', $name);
            $group->save();
            $modx->user->joinGroup($name);
        }else echo 'GROUP exists. ';
    
        $res_group = $modx->getObject('modResourceGroup', array('name' => $name));
    
        if(!$res_group){
             $res_group = $modx->newObject('modResourceGroup');
             $res_group->fromArray(array('name'=>$name,'private_memgroup'=>0,'private_webgroup'=>0));
             $res_group->save();
        }else echo 'RES_GROUP exists. ';
        
        $doc_folder = $modx->getObject('modResource', array('alias' => $id.'-uploads'));
        
        if(!$doc_folder){
            $upload_doc = $modx->getObject('modResource', array('alias' => 'uploads'));
            $upload_id = $upload_doc->get('id');
            
            $doc_folder = $modx->newObject('modResource');
            $doc_folder->fromArray(array(
                                           'alias' => $id.'-uploads',
                                           'pagetitle' => $id.'-uploads',
                                           'longtitle' => $id.'-uploads',
                                           'description' => $id.'-uploads: cartella di upload utente',
                                           'parent' => $upload_id,
                                           'isfolder' => 1,
                                           'createdby' => $id
                                           ));
            $doc_folder->save();
            $doc_folder->joinGroup($res_group);
            
            //set the resourceGroupAccess policy
            $resourceGroupAccess = $modx->newObject('modAccessResourceGroup');
            $resourceGroupAccess->set('target', $res_group->get('id'));
            $resourceGroupAccess->set('principal_class', 'modUserGroup');
            $resourceGroupAccess->set('principal', $group->get('id'));
            $resourceGroupAccess->set('authority', 9999);
            $resourceGroupAccess->set('policy', 4 ); // 4 for Load, List and View
            $resourceGroupAccess->set('context_key', 'web');
            $resourceGroupAccess->save();
            
            //set the contextAccess policy
            $contextAccess = $modx->newObject('modAccessContext');
            $contextAccess->set('target', 'web');
            $contextAccess->set('principal_class', 'modUserGroup');
            $contextAccess->set('principal', $group->get('id'));
            $contextAccess->set('authority', 9999);
            $contextAccess->set('policy', 4 ); // 4 for Load, List and View
            $contextAccess->save();
            
        } else echo 'DOC_FOLDER exists. ';


    This code works and sets up everything properly.
    After that, i created a new static resource for a test pdf file, that is shown correctly.

    The problem is that, even protecting the static resource with its respective resource group, it's visible to anonymous users. This problem appears now also with protected resources in "Pannello Utente" resource group.

    Did i make some configuration mistake in setting up all this stuff? How it is possible that anonymous users can see these protected resources?
      • 42562
      • 1,145 Posts
      Hi,

      You say the code works properly?
      Did you verify this by scrutinizing the ACL that this code puts together automatically?

      I would diagnose like this:
      Manually create a usergroup with no access to the protected material
      Test if a member of this new group has access to those protected resources in question.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 38538
        • 30 Posts
        Quote from: donshakespeare at Apr 25, 2013, 12:11 PM
        Hi,

        You say the code works properly?
        Did you verify this by scrutinizing the ACL that this code puts together automatically?

        I would diagnose like this:
        Manually create a usergroup with no access to the protected material
        Test if a member of this new group has access to those protected resources in question.

        The code works in the meaning that it correctly sets up the new resource group, user group and its ACL, as i can check them from the manager pages.

        And yes, i tried your suggested diagnose and creating a new user, assigning it to a new usergroup with no access to the protected pages still makes this user (and anonymous too) view the protected pages...

        I know its a permission and ACL issue, but i really can't figure out it.. it seems right to me and used to work too... f**k!!!

        I'm writing here the current permission setup, hope it will help better understanding of my situation (using 2.2.4-pl):

        After registration, new users are being inserted in "Pubblicatori" usergroup with a Member (9999) role.
        This UserGroup has these two ACL set up (from the /manager/ point of view):
        - Context Access: context web, role Member-9999, access policy Object;
        - ResourceGroup Access: resource group Pannello Utente, role Member-9999, access policy Object, context web;

        When uploading pdf, new user-specific usergroup are being created as stated in previous posts, setting these ACL:
        - Context Access: context web, role Member-9999, access policy Load Only;
        - ResourceGroup Access: resource group username_1, role Member-9999, access policy Load Only, context web;

        UserGroups:

        • anonymous
        • Administrator
        • Pubblicatori => username_1, username_2, ..., username_n.
        • username_1 => username_1.
        • username_2 => username_2.
        • ...

        "Pubblicatori" UserGroup is related to the "Pannello Utente" ResourceGroup, as stated previously.
        With the user-specific UserGroup, a new ResourceGroup is being set up, assigning it the user-specific static resources.

        ResourceGroups:

        • Pannello Utente => page1, page2, page3, ...
        • username_1 => resource1, static_resource2...
        • username_2 => reousrce3, static_resource4...

        The problem: anonymous users can view page1, page2, page3 and resource1, static_resource2, resource3 etc. Users not in user-specific usergroup can view its resource in user-specific resource group.

        Any help/hint is welcome.
        [ed. note: mau1989 last edited this post 13 years, 5 months ago.]
          • 42562
          • 1,145 Posts
          If I wanted to protect the resources (not just objects) in resource-group Pannello Utente,
          I'd give Pubblicatori this access:

          CONTEXT ACCESS
          Context (web) -- Minimum Role (member 9999) -- Access Policy (Load, List & View or Publishers)

          RESOURCE ACCESS
          Resource Group (Pannello Utente) -- Minimum Role (member 9999) -- Access Policy (Load, List & View or Resource) -- Context (web)

          And to bar other groups, I'd use:
          CONTEXT ACCESS
          Context (web) -- Minimum Role (member 9999) -- Access Policy (Load, List & View)

          RESOURCE ACCESS
          Resource Group (Pannello Utente) -- Minimum Role (member 9999) -- Access Policy (Load Only) -- Context (web)


          I hope you find what you are looking for...
            TinymceWrapper: Complete back/frontend content solution.
            Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
            5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
            • 3749
            • 24,544 Posts
            Maybe I'm misreading your post, but Resources in a Resource group are only protected if that Resource Group is connected (by a Resource Group Access ACL entry) to a User Group that the user is *not* a member of.

            If you create a Resource Group ACL entry linking the Resource Group containing the Resources you want to protect to the Administrator user group, that will protect them from everyone who is not given explicit access in another Resource Group Access ACL entry.

            I explain it in this video: http://modxpo.eu/schedule/sessions/modx-revolution-security-permissions-system (fair warning, it lasts an hour).
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 38538
              • 30 Posts
              Quote from: donshakespeare at Apr 26, 2013, 06:48 PM
              If I wanted to protect the resources (not just objects) in resource-group Pannello Utente,
              I'd give Pubblicatori this access:

              CONTEXT ACCESS
              Context (web) -- Minimum Role (member 9999) -- Access Policy (Load, List & View or Publishers)

              RESOURCE ACCESS
              Resource Group (Pannello Utente) -- Minimum Role (member 9999) -- Access Policy (Load, List & View or Resource) -- Context (web)

              And to bar other groups, I'd use:
              CONTEXT ACCESS
              Context (web) -- Minimum Role (member 9999) -- Access Policy (Load, List & View)

              RESOURCE ACCESS
              Resource Group (Pannello Utente) -- Minimum Role (member 9999) -- Access Policy (Load Only) -- Context (web)


              I hope you find what you are looking for...

              Ok, but I don't want other groups or anonymous to have access policy "Load Only" on "Pannello Utente" resource group, i want them don't have access at all! I need that anonymous users shouldn't see the resources related to "Pannello Utente" cause they have to be registered and logged in to do that.

              Quote from: BobRay at Apr 26, 2013, 11:10 PM
              Maybe I'm misreading your post, but Resources in a Resource group are only protected if that Resource Group is connected (by a Resource Group Access ACL entry) to a User Group that the user is *not* a member of.

              If you create a Resource Group ACL entry linking the Resource Group containing the Resources you want to protect to the Administrator user group, that will protect them from everyone who is not given explicit access in another Resource Group Access ACL entry.

              I explain it in this video: http://modxpo.eu/schedule/sessions/modx-revolution-security-permissions-system (fair warning, it lasts an hour).

              Thank you Bob, but I already know how ACL works and i did this whole thing before, my problem is that it doesn't work anymore. If you read carefully my post, you should see that I already set up the Resource Group ACL and Context ACL for the given user groups, but anonymous users can still see these protected resources.

              I can try to explain better my situation if it is occurred...
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                I think this may be the problem:

                - ResourceGroup Access: resource group username_1, role Member-9999, access policy Load Only, context web;


                If your user-specific user group has Load Only access to the resource group... that means that other user groups do not have load access. However, both "list" and "view" may still be granted. Theoretically if they don't have load access they shouldn't be able to actually get the object they are listing or viewing, but I would try giving "Load, List & View" access to the resource group and see if that properly locks out the other users.

                (Unrelated to your question; but personally I would not recommend using this sort of system for managing user-specific files; it would probably be easier to just have the user upload to their own files/USER_ID/ directory with a simple custom snippet, and list that using a tool like "FileDownload R" to have them list/view/download them)
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 42562
                  • 1,145 Posts
                  @mau1989

                  Did you try that and it failed?
                  This is what I wrote
                  And to bar other groups, I'd use: ...
                  This means to PREVENT other groups...not giving them access to see the resource (but not get a 404 error page either).

                  What BobRay means is that a user-group would need to own a resource-group before that resource-group can become protected.

                  This still works, handsomely, for me in my MODX Revolution 2.2.(5-7)pl (traditional)
                    TinymceWrapper: Complete back/frontend content solution.
                    Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                    5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                    • 38538
                    • 30 Posts
                    Sorry, i didn't tried nothing yet cause I've been quite busy today, but I'll try all of your suggestion tomorrow and let you know if it works.

                    Thanks in advance to everyone, I'll post tomorrow bad or good news wink
                      • 38538
                      • 30 Posts
                      @donshakespeare: i tried to set resource access as you suggested
                      And to bar other groups, I'd use:
                      CONTEXT ACCESS
                      Context (web) -- Minimum Role (member 9999) -- Access Policy (Load, List & View)

                      RESOURCE ACCESS
                      Resource Group (Pannello Utente) -- Minimum Role (member 9999) -- Access Policy (Load Only) -- Context (web)

                      to anonymous user group, flushed permissions but resources connected to "Pannello Utente" resource gruop are still visible to anonymous...
                      I don't know if could helps, I'm using 2.2.4 on this server.

                      @Mark Hamstra: I tried to set "Load, List and View" to resource group but still no luck..
                      Anyway, FileDownloader R and FileDownloadLink snippet seems exactly what I'm looking for! I'm trying it right now