We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30765
    • 66 Posts
    Quote from: rthrash at Dec 17, 2008, 10:17 AM

    Does anyone see a problem with adding a further layer of protection to sites by adding the following rule to htaccess:

    RewriteCond %{QUERY_STRING} snippet\.reflect\.php [NC,OR]
    RewriteCond %{QUERY_STRING} reflect_base [NC,OR]
    RewriteCond %{HTTP_USER_AGENT} ^libwww-perl [NC]
    RewriteRule .* - [F,L]
    


    I think you should go further ... a 403 for all PHP in the assets folder. As earlier in this thread, I’ve disabled access to PHP files in the assets folder, and haven’t noticed a problem running the bundled plugins and snippets and a healthy selection of third-party scripts. If someone is shipping scripts that require PHP access inside the assets folder, that is *bad*, and you’d be wise to put a stop to it anyway.

    You clearly can’t rely on hosts to configure their sites safely, or on users to read the security notices, so it’s worth mitigating the hell out of your default install.

    (You can also turn RewriteEngine off, so MODx won’t be left responding to 404s in the assets folder, which is expensive.)

    Two cents, etc ...

    Cheers
    Matt
      • 33372
      • 1,611 Posts
      You might want to remove that restriction for /assets/modules/, and there are some other files that may also be affected (e.g., assets/js/htcmime.php, possibly some files in /assets/plugins/tinymcexxx/, and any custom PHP files saved in /assets/site/, /assets/templates/, etc. For example, I have a dynamic CSS file on one site that is a PHP file, and it’s in the main assets folder. I think I’ve also put some PHP audio jukebox scripts in /assets/flash in the past...

      So it might cause more grief than it’s worth for some folks, although it’s good to have it out there as an option for them that want it.

      To me this once again reinforces the trouble with mixing code and other files in the current assets folder, which thankfully will be resolved when Revolution comes out.
        "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
        • 33372
        • 1,611 Posts
        Quote from: tuatara at Dec 17, 2008, 03:31 PM

        You can also turn RewriteEngine off, so MODx won’t be left responding to 404s in the assets folder, which is expensive.
        That plus an ErrorDocument 404 seems like a very good idea indeed.
          "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
          • 30765
          • 66 Posts
          Quote from: ZAP at Dec 17, 2008, 05:02 PM

          You might want to remove that restriction for /assets/modules/, and there are some other files that may also be affected (e.g., assets/js/htcmime.php, possibly some files in /assets/plugins/tinymcexxx/, and any custom PHP files saved in /assets/site/, /assets/templates/, etc. For example, I have a dynamic CSS file on one site that is a PHP file, and it’s in the main assets folder. I think I’ve also put some PHP audio jukebox scripts in /assets/flash in the past...
          htcmime.php merely sends htc files with the correct mime type; it would be easier to set the mime type in the .htaccess file anyway. TinyMCE works fine for me (I haven’t checked the translations though); and anyone writing custom PHP files should really know what they’re doing. (Requests for PHP files could always be redirected to a static page, or custom 403, that explains PHP access is not allowed in assets.)

          Quote from: ZAP at Dec 17, 2008, 05:02 PM

          So it might cause more grief than it’s worth for some folks, although it’s good to have it out there as an option for them that want it.

          From a security perspective, I think it’s better to disallow access; those who are skilled enough to know what they’re doing will easily be able to allow specific script access.

          Cheers
          Matt
            • 33372
            • 1,611 Posts
            Quote from: tuatara at Dec 17, 2008, 05:20 PM

            From a security perspective, I think it’s better to disallow access; those who are skilled enough to know what they’re doing will easily be able to allow specific script access.
            I’m not saying it’s a bad idea; just trying to identify things that would need to be addressed in order to not break people’s existing installations. There certainly are other ways to deal with the htcmime.php file, so it would just need to be done differently in future releases. The assets/modules/ folder, on the other hand, would probably need to be an exception altogether.

            As long as this isn’t the only thing done to resolve this issue I think it’s fine. Not everyone uses Apache (and not all Apache installations allow for local .htaccess overrides), so while it would work for a large percentage of users it wouldn’t cover everyone. The most important change that I’d like to see in future releases is that all files with snippet code that is included just to be copied into the database be .txt files (not .php).
              "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
              • 3749
              • 24,544 Posts
              Quote from: ZAP at Dec 17, 2008, 05:29 PM

              Quote from: tuatara at Dec 17, 2008, 05:20 PM

              From a security perspective, I think it’s better to disallow access; those who are skilled enough to know what they’re doing will easily be able to allow specific script access.
              I’m not saying it’s a bad idea; just trying to identify things that would need to be addressed in order to not break people’s existing installations. There certainly are other ways to deal with the htcmime.php file, so it would just need to be done differently in future releases. The assets/modules/ folder, on the other hand, would probably need to be an exception altogether.

              As long as this isn’t the only thing done to resolve this issue I think it’s fine. Not everyone uses Apache (and not all Apache installations allow for local .htaccess overrides), so while it would work for a large percentage of users it wouldn’t cover everyone. The most important change that I’d like to see in future releases is that all files with snippet code that is included just to be copied into the database be .txt files (not .php).

              Having them be .txt files can be a pain for development since it means they can’t be executed in a debugger, may open in the wrong editor, and may not have the proper highlighting once loaded editor. They could be switched to .txt files on install but during development, it’s no fun to keep switching them back and forth. It might be better to have them be .inc files (or .cls for class files).

                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
                • 27708 MODX Staff
                • 2,502 Posts
                I am no expert at security but it seems to me that for the benefit of security all distributed files as snippets should remain as txt files. Yes it is a pain in development but you as the dev can easily rename it as php for dev and then either delete it or rename it for installation. I think that convenience for knowledgeable devs should come 2nd to security for unknowing users and installers.

                I do see lots of great debate here and a number of possible solutions.
                  Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                  • 33372
                  • 1,611 Posts
                  Quote from: BobRay at Dec 17, 2008, 05:42 PM

                  It might be better to have them be .inc files (or .cls for class files).
                  As far as security is concerned they could be shipped with any extension that’s not generally executable as PHP, but you also want users to be able to easily open them so that they can copy and paste the code into the Manager so I think .txt is still the best option.
                    "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
                    • 22303 MODX Staff
                    • 10,725 Posts
                    The best idea is not to ship components with the core at all so it’s not associated with the code that is vulnerable, and to make sure when you do author php files that are intended to be executed directly or as a snippet that you take necessary precautions in the code. Renaming php files to other file extensions and all these other workarounds are not only inconvenient and limiting IMO, but completely unnecessary unless you have register_globals On or some other attack vector (besides just some snippet php script) open in your environment.
                      • 32093
                      • 21 Posts
                      I’ve had major hacking problems with the reflect snippet.

                      dont know how they did it (im not a hacker) but they’ve launched DOS attacks, used my server as a spam machine, insert trojan horses.

                      I’d advise people to uninstall the reflect snippet until more is know about this!