We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49443
    • 14 Posts
    I am trying to restrict front-end access to all the resources in a context. So I tried only giving certain user groups and authorities higher than the access permissions. But still the (anonymous) users are able to see the front-end.

    So I've got three contexts: mgr, web and auth. The (anonymous) user group only has the following context access:

    Web
    Member - 9999
    Load Only

    But still the anonymous users are able to see the resources in the auth context. I also tried adding all the resources in the context inside a resource group (which was a tedious process). But that also didn't work.

    What am I missing?

    Thanks in advance!
      • 3749
      • 24,544 Posts
      First, whenever you make a change to the permissions, be sure you flush permissions *and* sessions and test from a browser where you're not logged in to the Manager (even in another window).

      One way to protect the resources in a context, is to add them to a resource group *and* connect that resource group to a user group that the (anonymous) user is not a member of with a Resource Group Access ACL entry.

      Another way is to create a Context Access ACL entry for the Administrator user group with a Context of 'auth'. That protects the whole context as long as the (anonymous) user group does not have a Context Access ACL entry with that context.

      An even simpler way to protect the resources in the front end is to add a tag for a snippet with this code to all templates:

      if (! $modx->user->get('userame') === '(anonymous)') {
          return '';
      }
      $modx->sendUnauthorizedPage();


      Unlike the first two methods, this won't prevent the pages from showing up in menus or getResources displays. It will just forward the users to the page designated in the unauthorized_page System Setting.
        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
        • 49443
        • 14 Posts
        Hi Bob, thanks for the reply.

        Since I want to hide all the resources in a context, I'd like to go with the ACL tied to the 'auth' context. So what I did was give the anonymous group ONLY load permissions on the 'web' context.

        About flushing the permissions: It might sound stupid but I can only find the Flush permissions button on the currently logged in user. I tried clearing the cache, forcing all to log out and I'm testing on an incognito chrome window just to be sure I don't have a valid session. I'm using 2.3.2-pl btw.

        Thanks for your time!
          • 3749
          • 24,544 Posts
          Quote from: handyface at Jan 11, 2015, 05:48 AM
          Hi Bob, thanks for the reply.

          Since I want to hide all the resources in a context, I'd like to go with the ACL tied to the 'auth' context. So what I did was give the anonymous group ONLY load permissions on the 'web' context.

          Be sure you also create a Context Access ACL entry linking the auth context to the Administrator group (or some group, anyway). In theory, that will make it a "protected" context and its resources should be completely invisible to anyone who isn't explicitly given rights to it.
            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
            • 49443
            • 14 Posts
            This issue is really frustrating. I did all you suggested before I started this post but still there's a serious issue with the permissions. Is there any way to properly debug permission issues on a webserver? I have managed to find the session data of an anonymous user by looking up their PHPSESSID in the database. This is what's in it:

            modx.user.contextTokens|a:0:{}
            modx.user.0.resourceGroups|a:1:{
              s:4:"auth";a:0:{}
            }
            modx.user.0.attributes|a:1:
            {
              s:4:"auth";a:4:{
                s:16:"modAccessContext";a:1:{
                  s:3:"web";a:1:{
                    i:0;a:3:{
                      s:9:"principal";i:0;
                      s:9:"authority";s:1:"0";
                      s:6:"policy";a:1:{
                        s:4:"load";b:1;
                      }
                    }
                  }
                }
                s:22:"modAccessResourceGroup";a:0:{}
                s:17:"modAccessCategory";a:0:{}
                s:28:"sources.modAccessMediaSource";a:0:{}
              }
            }


            It looks like the normal web access policy is included in the AUTH context like it is automatically inherited or something. Is this even supposed to happen or is it a bug?
              • 49443
              • 14 Posts
              It looks like the permissions are acting really weird. Even when I remove the web load access of the anonymous group, they still have access..

              I should also say that the context is running on a different subdomain and I have the session_cookie_domain set to '.<mydomain>.<ext>' to preserve sessions on the domains. That works properly. I've even tried different php versions on the server, but absolutely nothing is making the context content hidden from (anonymous). Any idea on how to debug this? any help would be highly appreciated. [ed. note: handyface last edited this post 11 years, 8 months ago.]
                • 3749
                • 24,544 Posts
                Are *any* of the permissions working on the second domain? Have you verified that the $_SESSION is the same when a user goes from one domain to the other? Is there a reason to have the other context on a separate domain? I suspect that's causing your problem.
                  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
                  • 49443
                  • 14 Posts
                  Yes, the sessions are properly working. I've set up an 'Author' user group on the 'auth' subdomain, and they are able to log in to the manager, and view unpublished content on the front-end.

                  What DOESN'T work however is the following: Whenever I delete the (anonymous) policy on the 'web' context (so that leaves only the administrator policy), the site is still approachable by the users not logged in. So it's safe to say that the error is happening across the contexts. I should note that this install came from a local wamp and I used the modx guide to move this installation to a live server. I did not have the new context implemented before the move so I don't know if it's because of the server switch.

                  I'm thinking of checking out your sitecheck tool just to be sure that my ModX install is... 'sane'. Seeing how much you've tried to help me, it's only fair to give something back. I'll report the results after I tried the tool. [ed. note: handyface last edited this post 11 years, 8 months ago.]
                    • 49443
                    • 14 Posts
                    So I've just ran your tool. Though there's some issue when running it in the manager (the test results can't scroll), I was able to run it outside modx just fine. The tool did give some errors: the database and tables had the wrong collation. I've fixed that now. Sitecheck now reports no errors. But the anonymous ACL error still persists.
                      • 3749
                      • 24,544 Posts
                      Thanks for buying SiteCheck. smiley

                      I'm not an expert on diagnosing cross-context issues (I avoid contexts whenever possible). Hopefully, someone else can help.

                      This probably isn't the problem, but make sure the site_url tag in the head section of your templates is called uncached (with the exclamation point):

                      <base href="[[!++site_url]]" />


                        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