Login Security

The features of Facebook Login such as access tokens and permissions make it safe and secure for people and apps to use, but there are some security steps that apps need to implement themselves.

Video

From F8 2015, Jonathan Gross and Brent Dorman look at ways to increase the security of your Facebook Login integration.

Security Checklist

This list below should be considered the absolute minimum that all apps using Facebook Login should implement. Other features will be unique to your app and you will need to always think about how to make your app as secure as possible. Apps that are not secure will lose the trust of their audience and people will stop using them.

Never include your App Secret in client-side or decompilable code.

Sign all server-to-server Graph API calls with your App Secret.

Use unique short-term tokens on clients.

Don't trust that access tokens in use by your app were actually generated by your app.

Use the state parameter when using the login dialog.

Use our official SDKs where possible.

Reduce your app's attack surface area by locking down your Facebook app settings.

The App Secret

The App Secret is used in some of the Login flows to generate access tokens and the Secret itself is intended to secure usage of your App to only those that are trusted. The secret can be used to easily create an App Access Token which can make API requests on behalf of any user of the app, which makes it extremely important that an App Secret is not compromised.

Therefore the App Secret or an App Access token should never be included in any code that could be accessed by anyone other than a developer of the app. This applies to all methods of code that are not secured like client-side code (such as HTML or Javascript) or native apps (such as iOS, Android or Windows desktop apps) that could be decompiled.

We recommend that App Access Tokens should only be used directly from your app's servers in order to provide the best security. For native apps, we suggest that the app communicates with your own server and the server then makes the API requests to Facebook using the App Access Token. For this reason, if your 'App Type' under Advanced Settings in the App Dashboard is set to Native/Desktop we assume that your native app contains the App Secret or an App Access Token in the binary, and we do not allow calls signed with an App Access Token to proceed. The API will behave as though no access token was provided.

If your App Secret is compromised, you should reset it immediately in the Basic Settings of your App Dashboard. When you start the reset process, you can specify a number of hours that the compromised secret will continue to work for when making requests, however anything sent from Facebook (such as signed requests) will use the new secret straight away, so you must adjust your code to expect it as soon as possible.

Secure Server-side Calls with appsecret_proof

You can reduce your exposure to malware and spammers by requiring server-to-server calls to Facebook's API be signed with the appsecret_proof parameter. This topic is covered in our Securing Graph API Calls documentation.

Secure Client-side Calls with Short-term Tokens and Code Flow

In some configurations, apps will reuse a long-term token across multiple clients. Don't do this. Instead use short-term tokens that are generated with the code flow, as described in our access token documentation.

Token Hijacking

To understand how this happens, imagine a native iOS app that wants to make API calls, but instead of doing it directly, communicates with a server owned by the same app and passes that server a token generated using the iOS SDK. The server would then use the token to make API calls.

The endpoint that the server uses to receive the token could be compromised and others could pass access tokens for completely different apps to it. This would be obviously insecure, but there is a way to protect against this - access tokens should never be assumed to be from the app that is using them, instead they should be checked using debugging endpoints.


State Parameter

If you're using the Facebook login dialog on your website, be sure to use the optional "state" parameter. This unique string parameter guards your application against Cross-site Request Forgery attacks.

Lock Down Your Facebook App Settings

Motivation disable any authentication flows that the app does not use to minimize attack surface area.

  • Use code-generated short-term access tokens in clients instead of client-generated tokens or server-provided long-term tokens. The code-generated short-term access tokens flow requires the app server to exchange the code for a token, which is more secure than obtaining a token in the browser. Apps should prefer using the this flow whenever possible to be more secure – if an app only enables this flow, malware running on a user’s computer cannot obtain an access token to abuse. Learn more in our access tokens documentation.

  • Disable Client OAuth Login if your app does not use it. Client OAuth Login is the global on-off switch for using OAuth client token flows. If your app does not use any client OAuth flows, which include Facebook login SDKs, you should disable this flow. Note, though, that you can't request permissions for an access token if you have Client OAuth Login disabled. This setting is found in the Products > Facebook Login > Settings section.

  • Disable Web OAuth Flow or Specify a Redirect Whitelist. Web OAuth Login settings enables any OAuth client token flows that use the Facebook web login dialog to return tokens to your own website. This setting is in the Products > Facebook Login > Settings section. Disable this setting if you are not building a custom web login flow or using the Facebook Login SDK on the web.
  • When this setting is enabled you are required to specify a list of OAuth redirect URLs. Specify an exhaustive set of app URLs that are the only valid redirect URLs for your app for returning access tokens and codes from the OAuth flow.
  • Disable embedded browser OAuth flow if your app does not use it. Some desktop and mobile native apps authenticate users by doing the OAuth client flow inside an embedded webview. If your app does not do this, then disable the setting in Products > Facebook Login > Settings section.
  • Disable mobile single sign on flows if your app does not use them. If your app does not use iOS or Android Login, disable the ‘Single Sign On’ setting in the iOS and Android sections of Settings > Basic .

The App Dashboard contains a number of additional settings which allow developers to shut down areas of attack that might otherwise lead to security issues:

  • Basic > App Secret if your app secret is ever compromised, you can reset it here.
  • Basic > App Domains use this to lock down the domains and subdomains which can be used to perform Facebook Login on behalf of your app.
  • Advanced > App Type when you create a native app for mobile or desktop and include the app secret within, set this to Native/Desktop to protect against your app being decompiled and your app secret stolen.
  • Advanced > Server IP Whitelist specifies a list of IP addresses from which Graph API calls can be made with your app secret. Graph API calls made with your app secret from outside of this range will fail. Calls made with user access tokens are not affected by this setting.
  • Advanced > Update Settings IP Whitelist locks down the IP addresses from which someone can modify these app settings to a specific range. Take care setting an IP Whitelist on residential broadband. If your IP address changes you will lose the ability to edit your app's settings.
  • Advanced > Update Notification Email notifies an email address whenever any app setting is changed in the App Dashboard.
  • Advanced > Stream post URL security this will stop your app from publishing any URLs that don't point back to a domain it owns. This will not always be useful, specifically if you know your app will publish links to other sites.