Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP Whitelist Check for Creating Credentials #49

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

spiridonovpolytechnic
Copy link

@spiridonovpolytechnic spiridonovpolytechnic commented Apr 26, 2017

Dear Benjamin,
I have added a whitelist functionality for creating credentials. It is an additional (optional) layer of security and also allows a simple method of authentication (without logging in) by limiting creation of credentials to specific IP addresses.
The summary of additions are as follows:
config.php:

  • added a boolean flag to check against whitelist and added a whitelist array for CIDR IP ranges

security.php:

  • added a function to check an IP address against an array CIDR ranges

pw.php:

  • added a check of client IP against whitelist if the whitelist flag is set
  • navbar is now only displayed to whitelisted IP addresses
  • null URL argument branch of the code is now only available to whitelisted IP addresses
  • post URL argument branch of the code is now only available to whitelisted IP addresses

edit:
cleaned up text formatting

@bemosior
Copy link
Owner

Thanks for contributing this! I'll take a look momentarily.

@bemosior
Copy link
Owner

Overall, this looks really good. I'd like to make two requests before merging this in:

  1. We should default $checkCreatorIpWhitelist to false in config.ini (just like we do with $requireApacheAuth) so folks setting it up for the first time have fewer things that could be misconfigured.

  2. I see what you were going for with conditionally displaying the nav menu, but I think it might be best to take advantage of the logic already present for handling Apache-based authentication for sake of consistency. When unauthenticated, the existing logic will display the nav, will not display the form, and will display an authentication error at the top. Try out the changes below and see if you agree with this approach. We could certainly make additional adjustments to improve the user-friendliness.

diff --git a/pwpusher_public/pw.php b/pwpusher_public/pw.php
index 7f88103..574f03f 100644
--- a/pwpusher_public/pw.php
+++ b/pwpusher_public/pw.php
@@ -27,11 +27,7 @@ print getHeader();

 //Print the navbar
 /** @noinspection PhpToStringImplementationInspection */
-if ($creatorIpOk)
-{
-    print getNavBar();
-}
-
+print getNavBar();

 //Find user arguments, if any.
 $arguments = getArguments();
@@ -50,7 +46,7 @@ if ($requireCASAuth) {
 }

 //If the form function argument doesn't exist, print the form for the user.
-if ($arguments['func'] == 'none' || $arguments == false && $creatorIpOk) {
+if ($arguments['func'] == 'none' || $arguments == false) {

     //Force CAS Authentication in order to load the form
     if ($requireCASAuth) {
@@ -64,7 +60,7 @@ if ($arguments['func'] == 'none' || $arguments == false && $creatorIpOk) {
         }

         //Fail Apache Authentication if configured but not successful
-    } elseif ($requireApacheAuth && empty($_SERVER['PHP_AUTH_USER'])) {
+    } elseif ($requireApacheAuth && empty($_SERVER['PHP_AUTH_USER']) || $checkCreatorIpWhitelist && !$creatorIpOk) {
         //This section is a courtesy check; PHP_AUTH_USER can possibly be spoofed
         //if web auth isn't configured.
         /** @noinspection PhpToStringImplementationInspection */
@@ -77,7 +73,7 @@ if ($arguments['func'] == 'none' || $arguments == false && $creatorIpOk) {
     //Get form elements
     print getFormElements();

-} elseif ($arguments['func'] == 'post' && $creatorIpOk) {
+} elseif ($arguments['func'] == 'post') {

     //Force CAS Authentication in order to post the form
     if ($requireCASAuth) {
@@ -88,7 +84,7 @@ if ($arguments['func'] == 'none' || $arguments == false && $creatorIpOk) {
             $_SERVER['PHP_AUTH_NAME'] = $attributes[$casSamlNameAttribute];
         }

-    } elseif ($requireApacheAuth && empty($_SERVER['PHP_AUTH_USER'])) {
+    } elseif ($requireApacheAuth && empty($_SERVER['PHP_AUTH_USER']) || $checkCreatorIpWhitelist && !$creatorIpOk) {
         //This section is a courtesy check; PHP_AUTH_USER can possibly be spoofed
         //if web auth isn't configured.
         /** @noinspection PhpToStringImplementationInspection */

@spiridonovpolytechnic
Copy link
Author

Agreed on the default of having the whitelist disabled.
The reason for my implementation is that there are people who want to have the simplified authentication theme of "your IP is your authentication. " This way everyone on the intranet (either physically or via VPN) can use the utility without having to authenticate and everyone outside can only retrieve. I'll review the changes at lunchtime or when I get home.

@bemosior
Copy link
Owner

Yes, understood! The changes I suggest should accomplish the same, just using pre-existing constructs that (I think) provide a slightly more consistent and user-friendly experience. No rush!

thnilsen added a commit to thnilsen/PHPasswordPusher that referenced this pull request Oct 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants