We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24865
    • 289 Posts
    Either the forum’s search is insanely broken or I am just incapable of using it, but I reckon this bug should occur with ALL 3rd party frontend components.

    The problem is as follows. I use a little hack in all my connectors. In the time of VisionCart we came across the problem that the $site_id may not be made public on the frontend, since you then can hack the backend (which wasn’t as secure as it now is). So, we created the fix when $_REQUEST[’ctx’] was equal to web, HTTP_MODAUTH would contain the $site_id.

    Now, the $site_id is still present in the config, but has been adapted by the MODX’s session handler ($_SESSION[’modx.contextName.user.token’]). This is problematic, since MODX isn’t yet built when we need it for the connector (the connector creates it after HTTP_MODAUTH validation.

            /* ensure headers are sent for proper authentication */
            if (!isset($_SERVER['HTTP_MODAUTH']) && !isset($_REQUEST['HTTP_MODAUTH'])) {
                $this->body = $modx->error->failure($modx->lexicon('access_denied'));
    
            } else if (isset($_SERVER['HTTP_MODAUTH']) && $_SERVER['HTTP_MODAUTH'] != $siteId) {
                $this->body = $modx->error->failure($modx->lexicon('access_denied'));
    
            } else if (isset($_REQUEST['HTTP_MODAUTH']) && $_REQUEST['HTTP_MODAUTH'] != $siteId) {
                $this->body = $modx->error->failure($modx->lexicon('access_denied'));

    It get stuck after the 3rd else if check, where it is present AND doesn’t match the siteId, which is generated like so:

    $siteId = $_SESSION["modx.{$this->modx->context->get('key')}.user.token"];

    Aside from the strange code style, this is fine. The real problem is, we can’t access $_SESSION yet and the context siteId has a siteId_randomHash behind it, which is nowhere to be found.

    Oh oh oh, what to do? smiley
      @MarkGHErnst

      Developer at Adwise Internetmarketing, the Netherlands.
      • 2611
      • 394 Posts
      I think the suggested fix will be routing it through a snippet...though I’m curious
      as to how connectors can be used in the front-end anyway..
        Follow me on twitter: @b03tz
        Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
        CodeMaster
        • 24865
        • 289 Posts
        Using it in a snippet will defeat the entire purpose of frontend AJAX requests via a connector. I assume it was created for a reason. I’d hate to see a connector resource in my tree ...
          @MarkGHErnst

          Developer at Adwise Internetmarketing, the Netherlands.
        • What do you mean with "front end"? A CMP connector or something like a Quip reply form?

            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.
          • Quote from: ReSpawN at Jun 06, 2011, 09:31 AM

            Using it in a snippet will defeat the entire purpose of frontend AJAX requests via a connector. I assume it was created for a reason. I’d hate to see a connector resource in my tree ...

            Then just hide it using permissions smiley Snippets are a very easy (only?) way for front-end "connectors" and allow to set permissions.
              Jeroen Kenters

              MODX Professional | MODX Ambassador | Dutch MODX forums moderator

              website | twitter
              • 24865
              • 289 Posts
              Again, it would defeat the entire purpose of the connector. I get that MODX allows for like a dozen methods but via connector.php is still the best in my opinion. Next to that, in that case, each component would create a connector, which would be absolute bull.

              quipConnector
              twitxConnector
              vcConnector

              See what I mean?
                @MarkGHErnst

                Developer at Adwise Internetmarketing, the Netherlands.
                • 28215
                • 4,149 Posts
                See how I do it in Gallery:

                https://github.com/splittingred/Gallery/blob/develop/assets/components/gallery/connector.php

                Note the web/phpthumb if check; thats the only front-end processor i’m running, and so I’m setting up the modauth var there.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 24865
                  • 289 Posts
                  Looks good, gonna give it a try after I read myself in into a prototype. I’ll post a reply when it works (or doesn’t). Thanks Shaun!
                    @MarkGHErnst

                    Developer at Adwise Internetmarketing, the Netherlands.
                    • 24865
                    • 289 Posts
                    Works like a charm, nice one! I reckon that the newest 3rd party components, which I would imagine to be 2.1.1+ native, don’t need the version compare portion?
                      @MarkGHErnst

                      Developer at Adwise Internetmarketing, the Netherlands.
                      • 28215
                      • 4,149 Posts
                      Quote from: ReSpawN at Jun 06, 2011, 02:54 PM

                      Works like a charm, nice one! I reckon that the newest 3rd party components, which I would imagine to be 2.1.1+ native, don’t need the version compare portion?
                      It is probably best to keep the version_compare in.
                        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com