This demo uses the same sample app as Internal Activity Communication via Implicit Intent. The app sends user_id and session_token (which are considered sensitive information) as extras in an implicit intent.
Because the intent is implicit, any application that registers an activity with an <intent-filter> that matches the action can receive it and extract those values.
packageorg.owasp.mastestappimportandroid.content.Contextimportandroid.content.Intent// SUMMARY: This sample demonstrates the insecure use of implicit intents for internal communication.classMastgTest(privatevalcontext:Context){funmastgTest():String{valr=DemoResults("0x01")// FAIL: [MASTG-TEST-0372] The app uses an implicit intent to start an internal activity.valimplicitIntent=Intent().apply{action="org.owasp.mastestapp.INTERNAL_ACTION"putExtra("user_id","12345")putExtra("session_token","abcde-fghij-12345")addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)}try{context.startActivity(implicitIntent)r.add(Status.FAIL,"Launched internal activity via implicit intent")}catch(e:Exception){r.add(Status.ERROR,e.toString())}/* // PASS: [MASTG-TEST-0372] The app uses an explicit intent for internal communication. val explicitIntent = Intent(context, InternalActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } try { context.startActivity(explicitIntent) r.add(Status.PASS, "Launched internal activity via explicit intent") } catch (e: Exception) { r.add(Status.ERROR, e.toString()) } */returnr.toJson()}}classInternalActivity:android.app.Activity(){overridefunonCreate(savedInstanceState:android.os.Bundle?){super.onCreate(savedInstanceState)valtextView=android.widget.TextView(this)textView.text="Internal Activity"textView.textSize=24ftextView.gravity=android.view.Gravity.CENTERsetContentView(textView)}}
rules:-id:mastg-android-implicit-intent-leaking-extraspatterns:-pattern:|$I=newIntent(...);...$I.putExtra($KEY,$VAL);...$CTX.startActivity($I);-pattern-not:|$I=newIntent($C,$CLASS);...-pattern-not:|$I=newIntent(...);...$I.setPackage(...);...$CTX.startActivity($I);-pattern-not:|$I=newIntent(...);...$I.setComponent(...);...$CTX.startActivity($I);message:"[MASVS-CODE-4] The app sends an implicit intent with extras. Any app that registers for this action can receive the data. Use explicit intents for internal communication."languages:[java]severity:WARNINGmetadata:summary:Detectsimplicitintentsthatcarryextraswithoutspecifyingatargetpackageorcomponent.
run.sh
123
#!/bin/bash# SUMMARY: This script uses semgrep to detect implicit intents that leak sensitive data via extras.NO_COLOR=truesemgrep--config../../../../rules/mastg-android-implicit-intent-leaking-extras.yml../MASTG-DEMO-0136/MastgTest_reversed.java--text>output.txt
The test case fails because the app attaches sensitive extras (user_id and session_token) to an implicit intent and dispatches it without constraining the recipient.
The reported dispatch does not name a target package or component and does not verify the selected handler's identity before dispatch. The reported block does not show a target-defining call such as setPackage, setClass, setClassName, setComponent, or an explicit Intent(context, Class) constructor. Any app that declares a matching <intent-filter> for org.owasp.mastestapp.INTERNAL_ACTION can become a candidate and receive the full extras Bundle.