Top 7 Tips in Securing Your WCF Services

In the world of building client consumable APIs, security is always a priority. Let it be a web service, WCF or a remoting service, they cannot be vulnerable because they directly expose the operational methods to the outside clients.

In this article I will concentrate on the WCF service and take you through the top 7 tips in securing a WCF service. The top 7 list is based on my own sagacity and picked from the list of OWASP recommendations.

Secure Communication

As a first point, the communication between the client and server should be secure. The intermediate hackers should not be able to interrupt the communication messages. In WCF there is a feature called Transfer Security, which is intended to make the communication a secure one. There are two types of Transfer Security modes.

1. Transport Security

The security will be enforced at the transport layer level. This means the transport layer will mask the plain message. Transport Security will help in maintaining the good performance level of the WCF service where as it can’t be used on the service that is hosted on the internet or on a network where there is an intermediate router or any other proxy server. It is best suited for the WCF services hosted on the intranet.

netTcpBinding has the default security mode as Transport.

2. Message Security

The communication message will be encrypted in this case. It is best suited for the WCF services that are hosted and available over the internet.

wsHttpBinding has the default security mode as Message.

Shown below is the sample web.config entry to set the security mode for a particular binding.

 <bindings>
                <wsHttpBinding>
                       <binding>
                             <security mode="Transport/Message"></security>
                       </binding>
                </wsHttpBinding>
         </bindings>

Authentication

Authentication is an important piece during the process of client and server communication. Basically the WCF service should ensure that it is serving the request of a legitimate client. Below are some of the tips to implement authentication.

1. In the case of intranet WCF services, you can better choose windows authentication. A powerful credential management and enforcement is guaranteed.

2. When you decide to use username and password validation then make use of the membership providers instead of implementing a custom authentication mechanism. It will provide you more sophistication with less development effort.

3. It is also advisable for the client not to hard code or configure the credentials, rather prompt the user every time.

4. If you plan to use custom authentication then make use of in build WCF classes like System.IdentityModel.Selectors.UserNamePasswordValidator to validate the user credentials.

Enable WCF Audit and Message Logs

In order to get the audit information, you need to enable the WCF Audit and message logs. It will allow you to monitor the incoming requests to your WCF service.

WCF Audit

WCF Audit will log the security events of your service. It includes authentication success or failure. The information will get logged to the event viewer’s security log or application log. Below is how the WCF auditing feature has to be enabled.

    <behaviors>
      <serviceBehaviors>
        <behavior>
                     <serviceSecurityAudit auditLogLocation="Security" suppressAuditFailure="True" serviceAuthorizationAuditLevel="SuccessOrFailure" messageAuthenticationAuditLevel="SuccessOrFailure"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

Message Logs

Enabling message logs will log the incoming messages that are processed by the service onto the configured logs. The message logging can be enabled by configuring the below mentioned tag and its attributes.

<diagnostics>
                <messageLogging logEntireMessage="True"></messageLogging>
</diagnostics>

These WCF process instrumentation logs will help you in investigating potential hack attempts.

Use Replay Detection Feature

Some hackers may well intercept the WCF request message and try to replay those requests multiple times. This can be prevented using a WCF feature called replay detection. In order to create replay detection a custom binding is required. Its security tag’s local client and service settings should be configured with the below attribute values.

1. replayCacheSize

2. maxClockSkew

3. replayWindow

Exception Handling – Fault Contracts

Another important security part to take care of while developing a WCF service is not to disclose detailed exception information like the exception message or the stack trace to the client application. It is always recommended to use the FaultContracts to transport any operation failure with generic error information.

Host the Service on IIS

Host the WCF service on IIS in order to take full advantage of the IIS features like authentication, certificate set up and other processing features.

Enable SSL

The WCF service should be hosted under SSL in order to create trust between the clients. This will provide the confidence to the clients that they will not get into any phishing attacks.

Happy reading!



Related Articles

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

  • Live Webinar Tuesday, August 26, 2014 1:00 PM EDT Customers are more empowered and connected than ever, and the customer's journey has grown more complex. Their expectations are growing and trust is diminishing as they may interact with multiple brands through web, mobile and social channels. Considering 70% of the buying process in a complex sale is already complete before prospects are willing to engage with a live salesperson -- it's critical to understand your customers and anticipate their needs.* …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds