admin管理员组文章数量:1296469
I've run across the following snippet in themes from time to time:
if ( ! defined('ABSPATH')) exit('restricted access');
It's at the beginning of some (all?) PHP files in a theme and it's supposed to prevent direct access of the file by nefarious sources.
I see that this isn't included in Twenty Ten or Eleven and I've never seen it recommended in official WordPress documentation. It seems like a good idea to me, but I also don't know enough about security to judge it and can't find much with Google.
Is this something I should have in my custom themes? If so, should it be in all PHP files or just some?
I've run across the following snippet in themes from time to time:
if ( ! defined('ABSPATH')) exit('restricted access');
It's at the beginning of some (all?) PHP files in a theme and it's supposed to prevent direct access of the file by nefarious sources.
I see that this isn't included in Twenty Ten or Eleven and I've never seen it recommended in official WordPress documentation. It seems like a good idea to me, but I also don't know enough about security to judge it and can't find much with Google.
Is this something I should have in my custom themes? If so, should it be in all PHP files or just some?
Share Improve this question asked Aug 24, 2012 at 22:47 mrwwebmrwweb 10.3k5 gold badges40 silver badges75 bronze badges 3 |1 Answer
Reset to default 31Usually, you don’t need it. But … there is at least one edge case:
- If a theme file is a template part,
- and it is using global variables from the calling context (parent file),
- and register_globals is
on
, - and it is just using these variables without any security check …
… an attacker can call this file, set the missing variables with GET
or POST
and make the theme file print those out. And then there is a security problem.
So … the best option is not a context check like the one from your example, but good code: avoid global variables, check their content before you print it out.
本文标签: securityWorthwhile to restrict direct access of theme files
版权声明:本文标题:security - Worthwhile to restrict direct access of theme files? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741622031a2388867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
defined('ABSPATH') OR exit;
– kaiser Commented Jan 14, 2013 at 16:16defined('WPINC') ? : die();
:P – Tim Elsass Commented May 11, 2017 at 13:19