ServiceStack Request Filter to Require Secure Connection

This code snippet provides a Request Filter to make sure your ServiceStack services are being called via HTTPS.  If not, it returns a 403 code.

public class SecureRequestFilterAttribute : Attribute, IHasRequestFilter{    public IHasRequestFilter Copy()    {        return this;    }    public int Priority    {        // https://github.com/ServiceStack/ServiceStack/issues/119        // By setting priority to -100, this filter will be applied first.        get { return -100; }    }    public void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)    {        // https://groups.google.com/d/msg/servicestack/7JnQ8eLf36M/JFx2g7xEeEkJ        if (!req.IsSecureConnection)        {            res.StatusCode = (int)HttpStatusCode.Forbidden;            res.Close();        }    }}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s