Best way to restrict access by IP address?

One way is using a HttpModule. From the link (in case it ever goes away): /// <summary> /// HTTP module to restrict access by IP address /// </summary> public class SecurityHttpModule : IHttpModule { public SecurityHttpModule() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(Application_BeginRequest); } private void Application_BeginRequest(object source, EventArgs e) { … Read more

difference between http.context.user and thread.currentprincipal and when to use them?

The first thing that the HttpApplication object does when it acquires a thread is to set the thread’s principal to the HttpContext’s principal. This syncs up the principals. If, however, you go and set the Thread’s principal later on, the HttpApplication internally still has a different principal set for the user context. This is why … Read more

How to manage installation from Unknown Sources in Android Oreo?

For starters, your application needs to declare a targetSdkVersion of 26 (API level of Android Oreo) or higher in your build.gradle or AndroidManifest.xml for all this to work. Then on to answer the questions above: How to check whether I’m allowed to request a package install? You can check this using getPackageManager().canRequestPackageInstalls() anywhere in your … Read more

Proper session hijacking prevention in PHP

Your configuration is awesome. You definitely read up on how to lock down php sessions. However this line of code negates a lot of the protection provided by your php configuration: session_id(sha1(uniqid(microtime())); This is a particularly awful method of generating a session id. Based on your configurations you are generating the session id from /dev/urandom … Read more

When to use filter_input()

Well, there are going to be differing opinions. My take is that you should always use it (or, the filter extension in general). There are at least 3 reasons for this: Sanitizing input is something you should always do. Since the function gives you this capability there is really no reason to find other ways … Read more

Understanding CSRF

The attacker has no way to get the token. Therefore the requests won’t take any effect. I recommend this post from Gnucitizen. It has a pretty decent CSRF explanation: http://www.gnucitizen.org/blog/csrf-demystified/

How to pin the Public key of a certificate on iOS

In case you are in need of knowing how to extract this information from the certificate in your iOS code, here you have one way to do it. First of all add the security framework. #import <Security/Security.h> The add the openssl libraries. You can download them from https://github.com/st3fan/ios-openssl #import <openssl/x509.h> The NSURLConnectionDelegate Protocol allows you … Read more