We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23754
    • 13 Posts
    Quote from: ZAP at Feb 14, 2008, 06:56 PM


    I got the security notice by email... but which file do I have to patch around line 52?

    The code that you need to patch is actually not in a file. It’s the Search Highlighting plugin, which you can edit via the Manager in Resources -> Plugins. That code is saved into the database, not stored in a file.

    Thanks, Zap. Done! Actually the dialog box does not display page numbers so I had to rely on the variable names.

    Posword
      • 33372
      • 1,611 Posts
      Quote from: posword at Feb 14, 2008, 07:10 PM

      Thanks, Zap. Done! Actually the dialog box does not display page numbers so I had to rely on the variable names.
      True. If you want to see the line numbers you have to copy and paste the code into a text editor that shows them. I think there is a plugin in the repository that adds them (and also does code highlighting), but I’ve never used it.

      But anyway you found it and patched it, and that’s what matters...
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 28073
        • 164 Posts
        Dear all,

        When confirmation of the vulnerabilities was done, another problem was noticed.
        I posted this another problem to the "Private Moderator Team forum".
        Please,see this forum.

        Sincerely yours,
          • 19033
          • 892 Posts
          Dear all,

          I posted this another problem to the "Private Moderator Team forum".
          It is the following.
          http://modxcms.com/forums/index.php/topic,22843.0.html

          We do not know where we should contribute about these problem.
          If it is not suitable that we contribute it there, Please tell us where we should contribute these.
          Sincerely yours,
          MEGU

            • 33372
            • 1,611 Posts
            Quote from: MEGU at Feb 15, 2008, 06:35 AM

            Dear all,

            I posted this another problem to the "Private Moderator Team forum".
            It is the following.
            http://modxcms.com/forums/index.php/topic,22843.0.html

            We do not know where we should contribute about these problem.
            If it is not suitable that we contribute it there, Please tell us where we should contribute these.
            Sincerely yours,
            MEGU



            I would post about this to the AjaxSearch subforum. That way kylej and others can take a look at your code and see what they make of it. I don’t have time to review this right now, but I would expect that AjaxSearch uses the MODx dbAPI instead of regular PHP queries and that probably negates most possible SQL injection attacks.
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn't very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 5811
              • 1,717 Posts
              Dear all,

              the $docgrp variable incriminated in http://seclists.org/bugtraq/2008/Feb/0068.html is used as follow in the dosearch function of the includes/ajaxSearch.inc.php:
                if ($docgrp) {
              		$tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid LEFT JOIN $tbl_dg dg ON sc.id = dg.document";
                  $qry_sql .= " (ISNULL(dg.document_group) OR dg.document_group IN ({$docgrp})) AND ";
                } else {
                  $tbl_sql = " LEFT JOIN $tbl_stc stc ON sc.id = stc.contentid ";
                  $qry_sql .= " sc.privateweb = 0 AND ";
                }

              So, as $docgrp is used in a IN statement and with $docgrp enclosed by parentheses, I am interesting to know how this "where" clause statement could be hacked.
              Nevertheless, for security, i suggest to strip unwanted characters from the $docgrp variable by a specific strip_id function called before the use in the select statement. Here is a short demonstration of this specific function
              <?php
              $text = "12,11,13";
              echo strip_id($text);
              
              echo "<br>";
              
              $text = "username = '' or '1=1'";
              echo strip_id($text);
              
              function strip_id($text){
              
                  $mReg = '~([^0-9,]*)~';   // 
              
                  $text = preg_replace($mReg,'',$text);
                  return $text;
              }
              ?>
              The results of this short test is as awaited:
              12,11,13
              11
              Let me know if this strip_id function that i will use on $dogrp is enougth to avoid XSS and sql injection.

              Here is an interesting article about these subjects : http://www.securityfocus.com/infocus/1864
                • 33372
                • 1,611 Posts
                Hmm... Well, looking through the AjaxSearch code it seems as if there are some queries executed with standard PHP syntax and others that use the MODx dbAPI. And then delving a bit deeper into the MODx dbAPI it looks to me as if it relies on calling the escape method in order to sanitize queries from injection.

                So I think for consistency’s sake I would use the escape function from the db object that’s built into MODx, which looks like this:

                   function escape($s) {
                      if (function_exists('mysql_real_escape_string') && $this->conn) {
                         $s = mysql_real_escape_string($s, $this->conn);
                      } else {
                         $s = mysql_escape_string($s);
                      }
                      return $s;
                   }


                As you can see, this function relies on mysql_real_escape_string to replace potentially dangerous characters. I would think that this is sufficient to avoid injection attacks, but if not then it would probably be best to add additional character replacement to this function so that the benefits are carried over to all MODx resources that use this method. And it would be ideal to promote the value of using the MODx API and using the escape method among all resource developers (perhaps there should even be a checklist of security and other things to review before submitting a new resource to the repository).

                I’m not sure if AjaxSearch is always executed with the MODx API available, so if it is a special case for that reason then it might not be able to use this method exclusively (skimming the code it appears to be written to work without the API).

                None of this will be necessary anymore after 0.9.7 with xPDO is released, of course...
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 5811
                  • 1,717 Posts
                  Hi Zap. I understand the use of the mysql_real_escape_string function. I could add it like that:
                  $docgrp = mysql_real_escape_string($docgrp);
                  $docgrp = strip_id($docgrp);

                  In fact the code is built for the two modes (ajax mode without Modx api and non-ajax mode with api available).
                  When the ajaxMode is used, you have only the variables :
                    global $database_user;
                    global $database_password;
                    global $dbase;
                    global $table_prefix;
                    global $database_connection_charset;
                  And the modx api not available and native mysql queries required. Is it an heritage of the 1.6 version. And I haven’t investigate, if it ’s better or not to build a new modx object to use the api.
                    • 33372
                    • 1,611 Posts
                    I thought AjaxSearch might be a bit unique in that sense just from skimming the code (and not being very familiar with how index-ajax.php works; thanks for the summary). Do you think there’s a need to strip out more characters than what mysql_real_escape_string removes? If so, I would think that it would be better to add that code to the escape method and encourage developers to use that (although in the specific case of AjaxSearch it would also need to be duplicated there).

                    One advantage that I see to resource developers using the API is that it makes it much easier to identify and patch any possible vulnerabilities or other issues. Instead of having to review everyone’s code, you can just verify that they’re using the standard API calls and know how those work. And then if there’s ever a need to modify something in the API (for example, if it would be advisable to strip out more characters in the escape method), then changing it in that one place automatically applies the patch to all resources that use it.
                      "Things are not what they appear to be; nor are they otherwise." - Buddha

                      "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                      • 5811
                      • 1,717 Posts
                      From my point of view mysql_real_escape_string is enougth. I will update the code of ajaxSearch with this solution instead of a new specific strip_id function.

                      I agree with you with the use of API. But I haven’t still find the time to look if I could simply build a Modx object in the dosearch function of the ajaxSearch.inc.php file. If it is possible without time consumption, it could simplified greatly the code smiley

                      Thanks for your advices.