WhoBuilt

Security And Authentication In React Native

Oct 4, 2019· 25 min· 11K views·Watch on YouTube

Speaker

Kadi Kraman, a senior React Native engineer at Formidable, discusses app security and authentication at React Native EU 2019, hosted by Callstack.

Keep sensitive data off the client

Kraman says not to send information users should not see through API responses, include it in app code, or store it in AsyncStorage. In one example, an API returned email addresses and phone numbers that the app did not display; a security researcher found them in network traffic and reported the issue for a reward. Kraman’s lesson is to filter data and permissions on the server.

Inspect traffic and secure local storage

Kraman describes routing phone traffic through Charles Proxy to inspect API requests, with an SSL certificate installed to view encrypted traffic. She found that an app’s refresh-token exchange exposed an auth token that could be used to explore its API. AsyncStorage is unencrypted, so she recommends native secure storage options such as iOS Keychain and Android Shared Preferences, with encryption for sensitive data.

Understand OAuth and OpenID Connect

Kraman explains that OAuth 2 lets an app obtain a token after a user grants authorization, while OpenID Connect adds an authentication layer and supports sign-in through providers such as Google, Twitter, or GitHub. The flow sends the user to an authorization server, returns an authorization code to the app, then exchanges that code for a token. Client secrets offer no security in a native app because its code can be inspected.

Protect mobile OAuth with PKCE

On mobile, multiple apps may be able to handle the same redirect scheme, allowing a malicious app to intercept an authorization code through scheme squatting. Kraman explains that PKCE adds a code challenge to the authorization request and requires the matching key during the token exchange. She points to AppAuth for Android and iOS and React Native AppAuth as libraries that handle this flow.

Takeaways

  • Filter private fields and permissions on the server before returning API data.
  • Treat app code and network traffic as inspectable by users or third parties.
  • Keep auth tokens out of AsyncStorage; use native secure storage and encryption.
  • Use OAuth with PKCE for native app authentication, and rely on libraries such as React Native AppAuth.

Mentioned in this talk

Search inside this talk

What was claimed 9

Show all 9 facts

Related talks