LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-17-2020, 10:41 AM   #1
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Rep: Reputation: Disabled
Post How to disable directory listing for specific directories in Apache?


Hello,
I'm using CentOS 8 x86_64 and my server hosting a WordPress website. I scanned my WordPress website with a security scanner and it found some vulnerabilities about directory listing. Some lines of my Virtual Host file are:
Code:
<Directory "/var/www/WP">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
Some of my WordPress directories are browsable and when I open the URLs, then the content of the directories displayed:
Code:
https://example.net/wp-content/plugins/email-subscribers/
https://example.net/wp-content/plugins/contact-form-7/
How can I disable the directory indexing for those directories? I added below lines to my Virtual Host config file, but not worked:
Code:
<Directory /var/www/WP/wp-content/plugins/email-subscribers>
      Options -Indexes
</Directory>
<Directory /var/www/WP/wp-content/plugins/contact-form-7>
      Options -Indexes
</Directory>
I also did:
Code:
<Directory "/var/www/WP">
Options -Indexes +FollowSymLinks
AllowOverride all
Require all granted
</Directory>
But not matter. How can I solve it?

Thank you.
 
Old 11-17-2020, 10:56 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,486

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Create an empty index.php file in each folder, that's by far the easiest way.
 
1 members found this post helpful.
Old 11-17-2020, 11:06 AM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,759

Rep: Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224
Quote:
Originally Posted by TenTenths View Post
Create an empty index.php file in each folder, that's by far the easiest way.
Or even an empty index.html.
Personally, I turn off Indexes server-wide...I’ve yet to find a good reason to allow them...YMMV
 
1 members found this post helpful.
Old 11-17-2020, 11:18 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,486

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Quote:
Originally Posted by scasey View Post
Or even an empty index.html.
As the OP says they are running WordPress it's a fair assumption that index.php is configured as an index file.
While extremely unlikely, it is possible that index.html / index.htm isn't implemented / disabled

(Yes, I'm being pedantic to justify my answer )
 
Old 11-17-2020, 11:49 AM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,759

Rep: Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224
Quote:
Originally Posted by TenTenths View Post
As the OP says they are running WordPress it's a fair assumption that index.php is configured as an index file.
While extremely unlikely, it is possible that index.html / index.htm isn't implemented / disabled

(Yes, I'm being pedantic to justify my answer )
No worries 😉
 
Old 11-17-2020, 12:35 PM   #6
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
No other solution?
 
Old 11-17-2020, 12:40 PM   #7
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,486

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Sure, go messing around in your config file and disable it on an individual folder basis. Feel free to make life difficult for yourself by not going with a simple tried and tested solution.

Let us know how you get on.
 
1 members found this post helpful.
Old 11-17-2020, 01:55 PM   #8
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,634

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558

The more secure method is to disable it for all directories, and then enable it only on the specific ones you need it for (if any).

That way, you can't forget to create an index file for some obscure location that shouldn't be browsable.

 
1 members found this post helpful.
Old 11-17-2020, 03:42 PM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,759

Rep: Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224
You are restarting Apache every time you make a change, aren’t you? Don’t see a reason your config doesn’t work otherwise. Do you get any syntax errors?
Are you using symlinks to those directories? If so, see the fine print in the documentation for the Directory directive.

You’ve been given a couple of the best solutions.
 
Old 11-18-2020, 12:40 AM   #10
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
The more secure method is to disable it for all directories, and then enable it only on the specific ones you need it for (if any).

That way, you can't forget to create an index file for some obscure location that shouldn't be browsable.

Disable it for all directories, and then enable it only on the specific ones? How?
 
Old 11-18-2020, 12:41 AM   #11
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
You are restarting Apache every time you make a change, aren’t you? Don’t see a reason your config doesn’t work otherwise. Do you get any syntax errors?
Are you using symlinks to those directories? If so, see the fine print in the documentation for the Directory directive.

You’ve been given a couple of the best solutions.
I restarted Apache service and it is OK.
Are below lines wrong?
Code:
<Directory /var/www/WP/wp-content/plugins/email-subscribers>
      Options -Indexes
</Directory>
<Directory /var/www/WP/wp-content/plugins/contact-form-7>
      Options -Indexes
</Directory>
Can it because of SELinux?
 
Old 11-18-2020, 01:48 AM   #12
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
I shudder to think that user's like this one are allowed to put their servers on the interwebz...
Seriously, a misconfigured server open to any clients is actively endangering all of the internet.

Last edited by ondoho; 11-18-2020 at 01:50 AM.
 
1 members found this post helpful.
Old 11-18-2020, 06:38 AM   #13
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,634

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
Quote:
Originally Posted by n00b_noob View Post
Disable it for all directories, and then enable it only on the specific ones? How?
The Directory and Options directives are both well documented, so just read them:
https://httpd.apache.org/docs/current/mod/core.html#directory
https://httpd.apache.org/docs/current/mod/core.html#options

Changing Apache config requires a restart to take effect.

Using apachectl can check the config files for syntax errors before restarting.

 
1 members found this post helpful.
Old 11-18-2020, 09:09 AM   #14
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,759

Rep: Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224Reputation: 2224
n00b_noob...RTFM
 
1 members found this post helpful.
Old 11-19-2020, 04:15 AM   #15
n00b_noob
Member
 
Registered: Sep 2020
Posts: 436

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
The Directory and Options directives are both well documented, so just read them:
https://httpd.apache.org/docs/current/mod/core.html#directory
https://httpd.apache.org/docs/current/mod/core.html#options

Changing Apache config requires a restart to take effect.

Using apachectl can check the config files for syntax errors before restarting.

Thank you so much.
As I see in the link:
Code:
Context:	server config, virtual host, directory, .htaccess
And I added below lines to my Virtual Host file and restarted httpd service:
Code:
<Directory /var/www/WP/wp-content/plugins/email-subscribers>
      Options -Indexes
</Directory>
<Directory /var/www/WP/wp-content/plugins/contact-form-7>
      Options -Indexes
</Directory>
And:
Code:
$ sudo apachectl configtest
Syntax OK
Then why directory listing for that URLs are enable?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find specific named directory while excluding specific named directory sharky Linux - Newbie 6 01-17-2014 11:29 AM
Copy a directory into another directory while ignoring specific directories or files wh33t Linux - Newbie 14 05-16-2012 08:13 PM
[SOLVED] RHEL5 Apache Directory Listing for a directory thorinn Red Hat 8 02-02-2010 09:01 AM
Disable directory listing on apache in Debian Lenny poiuytrez Debian 4 06-18-2009 05:20 AM
Apache Directory Listing Of NFS Mount, cannot view directory list via apache luqmana Linux - Networking 2 12-19-2005 06:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration