We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2611
    • 394 Posts
    As we all know, when we execute an ajax request in the back-end we need a MODAUTH header
    that contains the $modx->site_id variable. If this variable is not set, the requests
    get’s a "access denied" error and the processor won’t load.

    I totally understand this behavior, but I can imagine that this site_id is a secure variable...
    One we do not want the front-end people to know about...so how would we route a request
    in the front-end of MODx.

    Say I have a javascript that requests the content of a basket. This basket is a processor
    in /core/components/mycomponent/processors/web/basket.php

    When I request this, it says access denied...because I’m not posting the MODAUTH variable.
    [edit]When i say, request this I mean the connector that includes this file of course[/edit]

    Should I create a seperate connector just for the front-end?
      Follow me on twitter: @b03tz
      Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
      CodeMaster
      • 28215
      • 4,149 Posts
      Are you sending a URL to connectors/ ? If so, then yes, you’ll need the HTTP_MODAUTH var.

      An alternative is to create a Resource that is just a connector Resource, and have in it a snippet that calls:

      $result = $modx->executeProcessor(array(
         'action' => 'web/basket',
         'processors_path' => $modx->getOption('core_path').'components/mycomponent/processors/',
      ));
      

      That will have the same affect. However, doing it this way allows people to just POST straight to that file on a whim, which could lead to spam or CRSF attacks. You’ll have to protect it some way; that’s what HTTP_MODAUTH solves.

      HTTP_MODAUTH can also be passed as a HTTP header called ’modAuth’ if you want, as well, if you don’t want to pass it as a GET/POST var.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 2611
        • 394 Posts
        Ok, so just to sum it up...we can use the MODAUTH header in the open? Everybody may know this
        variable...right?
          Follow me on twitter: @b03tz
          Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
          CodeMaster
          • 28215
          • 4,149 Posts
          I wouldn’t use it where someone could find it.

          My recommended method is that you create your own connector, and do your own protection against CRSF.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 2611
            • 394 Posts
            For now we have made it so that the connector sends the site_id internally when
            a web-context processor is requested. Every manager processor is just as safe
            and the front-end connectors can be called without the MODAUTH for now.
              Follow me on twitter: @b03tz
              Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
              CodeMaster