0

I have a series of JsonAPIs triggers within an Android app.

Question is:

If I have a token for auth. then app's users can easily capture the POST request and find the token, even if I hash the token within the app and send it to server, then compare it to the hashed token from DB users still can capture the hashed token...

Whats a true way to deal with this??

1 Answers1

1

AUTH TOKENS

If I have a token for auth.

Please bear in mind that a User Auth token only identifies who is in the request, not what is doing the request. Don't worry if you were not aware of this yet, because its a very usual misconception among developers of any level and background.

So lets' clear it up first...

The Difference Between WHO and WHAT is Accessing the API Server

I wrote a series of articles around API and Mobile security, and in the article Why Does Your Mobile App Need An Api Key? you can read in more detail the difference between who and what is accessing your API server, but I will quote some of the main points from it:

The what is the thing making the request to the API server. Is it really a genuine instance of your mobile app, or is it a bot, an automated script or an attacker manually poking around your API server with a tool like Postman?

The who is the user of the mobile app that we can authenticate, authorize and identify in several ways, like using OpenID Connect or OAUTH2 flows.

So think about the who as the user your API server will be able to Authenticate and Authorize access to the data, and think about the what as the software making that request in behalf of the user.

EVERYTHING IN THE CLIENT CAN BE CAPTURED OR EXTRACTED

If I have a token for auth. then app's users can easily capture the POST request and find the token, even if I hash the token within the app and send it to server, then compare it to the hashed token from DB users still can capture the hashed token...

No matter what technique you use in the end an attacker can always get hold on any secret you try hard to hide from him, the question is more how much effort he is willing to put in getting it from your mobile app and/or how much knowledge he have to perform such tasks.

Nowadays we have a plethora of tools to help security researchers or anyone one with bad intentions to reverse engineer a mobile app, like:

For MitM atttacks - mitmproxy

An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.

For static analysis - MobSF - Mobile Security Framework

Mobile Security Framework is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing framework capable of performing static analysis, dynamic analysis, malware analysis and web API testing.

For runtime code instrumentation - Frida

Inject your own scripts into black box processes. Hook any function, spy on crypto APIs or trace private application code, no source code needed. Edit, hit save, and instantly see the results. All without compilation steps or program restarts.

Despite this tools exist I still encourage you to employ as many defense techniques as you can afford into your mobile app, because not every attacker as the knowledge or is willing to spent too much time in your mobile app, when they have easier targets to attack.

POSSIBLE SOLUTION

Whats a true way to deal with this??

No true way exists, it's all about your special use case and how much resources you have and can afford to employ and are required by law to do so.

For APIs serving mobile apps you can employ the Mobile App Attestation concept that will allow your API server to have an high degree of confidence about what is doing the request to the API server, is it your genuine and untampered mobile app or is an attacker.

I recommend you to read this answer I gave to the question How to secure an API REST for mobile app?, specially the sections Securing the API Server and A Possible Better Solution.

DO YOU WANT TO GO THE EXTRA MILE?

In any response to a security question I always like to reference the excellent work from the OWASP foundation.

For Mobile Apps

OWASP Mobile Security Project - Top 10 risks

The OWASP Mobile Security Project is a centralized resource intended to give developers and security teams the resources they need to build and maintain secure mobile applications. Through the project, our goal is to classify mobile security risks and provide developmental controls to reduce their impact or likelihood of exploitation.

OWASP - Mobile Security Testing Guide:

The Mobile Security Testing Guide (MSTG) is a comprehensive manual for mobile app security development, testing and reverse engineering.

For APIS

OWASP API Security Top 10

The OWASP API Security Project seeks to provide value to software developers and security assessors by underscoring the potential risks in insecure APIs, and illustrating how these risks may be mitigated. In order to facilitate this goal, the OWASP API Security Project will create and maintain a Top 10 API Security Risks document, as well as a documentation portal for best practices when creating or assessing APIs.

Exadra37
  • 5,511
  • 1
  • 20
  • 34
  • THE MOST USEFUL ANSWER ever in all stacks!!! but there are two side question raised: **1st:** Is there a need of _Mobile App Attestation service implementation_ or there are some? **2nd:** this need a full teamwork between app dev. and API dev. ! no room for solo work by API dev. only? I thought about hashing **unix timestamp** that can be used only if its from 30s ago or something & expire after first usage... (this because of reduce needing of app dev. team's work and ig it more likely to break in case of disassembling app & and find the algorithm not with req. capture...) – Shahab Ouraie Jul 04 '20 at 21:44
  • 1
    1st question: Yes you have ready to use SaaS solution. – Exadra37 Jul 06 '20 at 10:13
  • 1
    2dn question: Implementing the Mobile App Attestation by one dev is possible but it would take a lot of your time. You can use the timestamp approach, but its easily reverse engineered by hackers. – Exadra37 Jul 06 '20 at 10:17
  • exactly, lot of time! any link there helping using which and how to SaaS? not very experienced in Android – Shahab Ouraie Jul 09 '20 at 02:04