Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was wondering how safe urls of the form "www.domain.com/index.php?page=xxxxx" are. I don't want something which could be exploited by giving values such as 'index.php' or '../../etc/passwd' or whatever. Is what I have below secure?
Having spent the last several minutes reading the code, it looks OK to me. Lets break it down:
1) you define a $pages array with the keys: main, aboutus, foo.
2) If the superglobal page does not exist or is null, you set it to main.
3) if it does exist and is not null, you "filter" it, which removes all characters except letters, digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
4) you then match the remaining data against the set of keys. This step is the critical part and you are actually white listing by verifying supplied data against a set of known test cases, which is the correct action. You do not "process" on any supplied data.
5) once you have conclusively set $page, either by matching an array key, you include the appropriate page.
As I said, I think this code will work as intended. I am wondering, though, why go through these convoluted steps instead of just using a case statement that matches main, aboutus, foo, or sets default (main)? and includes the appropriate line?
I was thinking of this thread this morning and I had an epiphany about an advantage to your approach. Your approach will let you pass in an array of sites and keys to a function and using this array, filter the results and return the correct page. If you have a lot of pages, code reuse of a tested algorithm would be better than recreating a hard coded case statement many times. I am not sure if you can pass parameters into a case block or not and I am not envisioning it working....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.