We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22851
    • 805 Posts
    Step 0. Set-up eForm in the standard way.

    Step 1. Create a snippet called eFormHelpPreventXSS and paste the code above into it.

    Step 2. Place the following just before each eForm snippet call:
    [[eFormHelpPreventXSS]]
    


    Step 3. Add the following parameter to your eForm calls:
    &eFormOnBeforeMailSent=`eFormHelpPreventXSS`
    


    Step 4. Do a few form submissions tests with:
    &
    

    or
    <?php echo 'XSS attack'; ?>
    

    or
    <img src="url to some valid image" />
    

    in the content/comments.

    If the & does not appear as &amp; within the source of the thankyou
    page, or if any of the other two appear in any form in the output,
    then the eFormHelpPreventXSS script is not working as it should.
      YAMS: Yet Another Multilingual Solution for MODx
      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
      • 26931
      • 2,314 Posts
      thanks PMS! smiley
        • 20413
        • 2,877 Posts
        Yeah THANKS!! smiley
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 16183
          • 1,390 Posts
          Mucho gracias!

          cheers/k
            • 24935
            • 160 Posts
            Maybe this anti-xss code should be worked into the next version of eForm. It could be on by default, with an option to disable it if you had a reason to do so and knew what you were doing.
              • 25663 MODX Staff
              • 12,272 Posts
              Quote from: rfoster at Aug 04, 2009, 09:20 AM

              Maybe this anti-xss code should be worked into the next version of eForm. It could be on by default, with an option to disable it if you had a reason to do so and knew what you were doing.
              That makes a lot of sense indeed. smiley
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 22851
                • 805 Posts
                Quote from: rthrash at Aug 04, 2009, 09:52 AM

                Quote from: rfoster at Aug 04, 2009, 09:20 AM

                Maybe this anti-xss code should be worked into the next version of eForm. It could be on by default, with an option to disable it if you had a reason to do so and knew what you were doing.
                That makes a lot of sense indeed. smiley

                Hmmm. Almost. The documentation states that the following datatypes are allowed:
                    *  string - No specific validation besides checking if it's empty if the field is required.
                    * date - Checks if it is a valid date (based on php's strtotime() function)
                    * integer - Checks if it is a number (does not check if it is in fact an integer)
                    * float - Checks if it is a number
                    * email - Checks if it's a valid email address using a simple regular expression
                    * file - (for file upload input) - checks if a size error occurs, does not currently check file type
                    * html - Same as string except that it converts line endings (\n) to <br /> tags
                


                The first eFormHelpPreventXSS function I posted strips all html from the input, and the most recent version doesn’t allow any html to be processed at all - so you wouldn’t quite get what you wanted when specifying html as the datatype, for example.

                Maybe a better approach would be to have one new datatype, which would be the default rather than string:

                * cleanstring - strips any valid html, php or xml from the input and escapes html characters.

                The code for this could be based on my first function

                To help prevent XSS a new filter could be introduced that could be used on individual fields:

                #NOCODE - prevents processing of a field if it contained any embedded html, php or xml.

                The code for this could be based on the strip_tags bit of my second function.
                  YAMS: Yet Another Multilingual Solution for MODx
                  YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                  Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                  • 25663 MODX Staff
                  • 12,272 Posts
                  PMS that would indeed be an appreciated addition. Any chance you could put a patch together?
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 22851
                    • 805 Posts
                    I’m happy to try to help with things that are beneficial to me too! I’ll have a look at the code and see what’s involved.

                    I work full time and when I’m not doing that I’m providing lots of YAMS support since people are starting test drive it. So I might not be able to deliver the speediest of patches, but I’ll do my best.
                      YAMS: Yet Another Multilingual Solution for MODx
                      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                      • 22851
                      • 805 Posts
                      When I looked closely at the code, I realised it didn’t work quite like I though it did. I have updated the documentation to clarify how the existing datatypes currently work and the potential risks should the data not be sanitised before it is used. This section could do with a review and check by someone else. Any volunteers?

                      Currently, if the $allowhtml parameter is false - the default, then tags are stripped from data with the string datatype, but not from data with the html datatype. Crucially, nothing is escaped no matter what the case. So, I have included a new datatype called safestring, from which code is always stripped and special HTML characters are always escaped. This is equivalent to the first eFormHelpPreventXSS function I posted. safestring is now the default should no validation rule be specified.

                      I also fixed a couple of minor bugs.

                      Please find attached my updated code and documentation. I have assumed that this would become version 1.4.4.7. Modifications to the code are enclosed in
                      // PMS START
                      ...
                      // PMS END
                      

                      blocks. (They’re unfortunate initials, I know...)
                        YAMS: Yet Another Multilingual Solution for MODx
                        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.