Search code examples
react-nativeoauthtwitter-oauth

Is it a security vulnerability to put TWITTER_CONSUMER_KEY / SECRET in client for oAuth1 Twitter Login?


All of the React Native Twitter Login Clients that I'm finding seem to be hard-coding the TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET into the the client code, rather than relying on a server to generate tokens and/or a twitter redirect URL.

  • Is this safe? (e.g. couldn't a consumer then DOS the API with the TWITTER_CONSUMER_KEY, causing the app to be rate limited?)
  • Is this the correct way to do it?
  • Is there a better / more secure way?

According to twitter's documentation, it seems like this is NOT the correct way to do this: "In the event that you believe that your API keys has been exposed, you should regenerate your API keys by following these steps" - Authentication best practices

Examples which specify that the consumer key/secret should be hardcoded:

Related questions:


Solution

  • Is it a security vulnerability

    Yes.

    Your app can be rate limited or flagged as malware/spam etc.

    Is there a better / more secure way?

    Basically only to have your own site auth (oauth2) done correctly and proxy specific requests from your clients, after validation or a simplified locked down site API that is then translated to the Twitter API.

    Why is this, Twitter app-only auth supports OAuth2, allows a secure negotiated handshake and then requests made using a Bearer token. In this mode you can make requests on behalf of your App, but without a logged in user. So can't post tweets or see private accounts or read DMs.

    For user-auth, Twitter only support OAuth1 and both the App and User are authenticated, but using a model that assumed plaintext http, so can't share a single token. Every single request needs to be made using consumer key/secret and signing the request. So there isn't a way to do this from a javascript client safely.