We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5393
    • 63 Posts
    Hi all,

    I really need your guys help and please let me know what to do. I create a login site using login snippet and inside the login site there are many html files and each files are linked to some songs and pdf uploaded to the "assets" file inside modx. I just want to ask how to block user to direct access to those files without login in to the site? I mean if the user know the path of those files by viewing source code of after login html, he/she can still access to those files without login in next time or share the full path of everyone. how can I set the access rights of those files in modx?

    Thanks
    Ernest

      • 42562
      • 1,145 Posts
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 5393
        • 63 Posts
        Thanks donshakepeare!

        have you use filelister before? we use modx 2.2.6 and wonder how risky it is to install this package?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You should really upgrade your MODX. There are some security vulnerabilities that are being actively used to hack sites.

          My personal preference is to use static resources to link to files. Being resources, they have all of the features of resources, including user validation. And the URLs are the URLs to the resource itself, instead of the path to the file. You can also have your files outside of the web root, so the only way to access them is through the static resource.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 5393
            • 63 Posts
            Quote from: sottwell at Apr 25, 2014, 06:14 AM
            You should really upgrade your MODX. There are some security vulnerabilities that are being actively used to hack sites.

            My personal preference is to use static resources to link to files. Being resources, they have all of the features of resources, including user validation. And the URLs are the URLs to the resource itself, instead of the path to the file. You can also have your files outside of the web root, so the only way to access them is through the static resource.

            Thanks sottwell for your help but can you explain more details about what you mean?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              It all depends on what features you want for your file downloads.

              I usually put my files in a directory above the web root, for example if my web root is "www" I'll have a directory "files" right next to it.

              Then I create a Media Source with a non-relative path such as /full/path/to/files/, and leave the URL blank since that has no meaning in this case - the file is streamed from the server's file system, not served as an HTML download.

              Then I create new Content Types (in the System menu) for each type of file, such as .pdf, set them as binary and with the proper mime type.

              Then I create a chunk that has the same path as the Media Source. This is because while you can use a media source to select the file to link to, Static Resources don't store the media source part of the path.

              So when I create a static resource for a file, in its Settings tab I select the proper Content Type and the Content Disposition as attachment, then in the Document tab I select my "files" media source, and select the file I want to link to. Then I add the chunk tags to the path that the static resource stores, so that the resource will end up with the full path to the file.
              [[$source_path]]rest-of-path/to/file.pdf


              Now you can use all the features of a resource, except the content field which holds the path to the file to be served. So you can search using the other fields, you can use getResources or Wayfinder to list them, you can assign them to a template so they can have TVs for tagging and filtering. The URL for the actual download will be the alias for the static resource, just like any resource's URL, so the actual path to your files is never displayed. And since the file is actually outside of the web root, nobody can get at it except through the links to the static resources.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 5393
                • 63 Posts
                Thanks sotwell for help. So if I follow the way you said to locate my files like PDFs inside my mods, do we still need to install snippets like filelister or file download to protect my files being access directly from the public? I try not to install snippets that are not needed by the system because there is always some risk to install new code to it. So the way u said is enough to protect the direct access from public right?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  locate my files like PDFs inside my mods
                  No, the files would be located outside of your web root directory. For example, on the MODX Cloud, the web root is "www":
                  /paas/cxxxx/www/

                  so my files would be in
                  /paas/cxxxx/files/


                  On my localhost MAMP-based web server environment, the web root is "htdocs":
                  /Applications/MAMP/htdocs/

                  so the files are in
                  /Applications/MAMP/files/


                  Likewise a standard cPanel managed shared hosting account, where the web root is called "public_html", MODX is installed as an add-on domain in a subdirectory of the web root:
                  /home/username/public_html/modx/

                  so the files are in
                  /home/username/files/


                  Since the files are outside of the web root, then they cannot be accessed with a regular HTTP URL request. MODX instead streams them as binary files, which can be offered for download or opened by the browser in the appropriate application or browser plugin (Adobe reader, for example, for .pdf files).

                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 5393
                    • 63 Posts
                    Hi sottwell, again thanks for your help! I am kind of following the way you said by creating static resources in resources tab and link my file(e.g. pdf) to the new static resources. Just wonder can I create a folder which I put all the resources (pdf files) and then I set the access right to this folder only and once?

                    Thanks
                    Ernest

                    Quote from: sottwell at Apr 26, 2014, 12:02 AM
                    locate my files like PDFs inside my mods
                    No, the files would be located outside of your web root directory. For example, on the MODX Cloud, the web root is "www":
                    /paas/cxxxx/www/

                    so my files would be in
                    /paas/cxxxx/files/


                    On my localhost MAMP-based web server environment, the web root is "htdocs":
                    /Applications/MAMP/htdocs/

                    so the files are in
                    /Applications/MAMP/files/


                    Likewise a standard cPanel managed shared hosting account, where the web root is called "public_html", MODX is installed as an add-on domain in a subdirectory of the web root:
                    /home/username/public_html/modx/

                    so the files are in
                    /home/username/files/


                    Since the files are outside of the web root, then they cannot be accessed with a regular HTTP URL request. MODX instead streams them as binary files, which can be offered for download or opened by the browser in the appropriate application or browser plugin (Adobe reader, for example, for .pdf files).

                      • 5393
                      • 63 Posts
                      Hi sottwell, again thanks for your help! I am kind of following the way you said by creating static resources in resources tab and link my file(e.g. pdf) to the new static resources. Just wonder can I create a folder which I put all the resources (pdf files) and then I set the access right to this folder only and once?

                      Thanks
                      Ernest

                      Quote from: sottwell at Apr 26, 2014, 12:02 AM
                      locate my files like PDFs inside my mods
                      No, the files would be located outside of your web root directory. For example, on the MODX Cloud, the web root is "www":
                      /paas/cxxxx/www/

                      so my files would be in
                      /paas/cxxxx/files/


                      On my localhost MAMP-based web server environment, the web root is "htdocs":
                      /Applications/MAMP/htdocs/

                      so the files are in
                      /Applications/MAMP/files/


                      Likewise a standard cPanel managed shared hosting account, where the web root is called "public_html", MODX is installed as an add-on domain in a subdirectory of the web root:
                      /home/username/public_html/modx/

                      so the files are in
                      /home/username/files/


                      Since the files are outside of the web root, then they cannot be accessed with a regular HTTP URL request. MODX instead streams them as binary files, which can be offered for download or opened by the browser in the appropriate application or browser plugin (Adobe reader, for example, for .pdf files).