Skip to content

Add demo for MASTG-TEST-0295 (GMS Security Provider Not Updated) - #3978

Open
Aspirant200715 wants to merge 2 commits into
OWASP:masterfrom
Aspirant200715:feature/demo-gms-security-provider
Open

Aspirant200715 wants to merge 2 commits into
OWASP:masterfrom
Aspirant200715:feature/demo-gms-security-provider

Conversation

@Aspirant200715

Copy link
Copy Markdown

This PR closes #3468

Description

This PR introduces a new practical demonstration for MASTG-TEST-0295 (GMS Security Provider Not Updated) under the MASVS-NETWORK testing category, fulfilling the request outlined in issue #3468.

In older versions of Android, the native cryptographic Security Provider frequently contains unpatched SSL/TLS vulnerabilities. Because OS-level updates are often unavailable for legacy devices, developers must rely on Google Play Services to "hot-patch" the Security Provider at runtime. This demo provides a concrete example of both vulnerable and secure implementations of this requirement.

Key Additions in this PR:

  1. MastgTest.kt:

    • Insecure Implementation (insecureNetworkCall): Simulates a common developer mistake where an HttpsURLConnection is established immediately without verifying or updating the Security Provider. On older devices, this leaves the application vulnerable to known SSL/TLS exploits.
    • Secure Implementation (secureNetworkCall): Demonstrates the proper, synchronous usage of ProviderInstaller.installIfNeeded(context). Crucially, this implementation includes the required Android best-practice exception handling:
      • Catches GooglePlayServicesRepairableException (e.g., when Play Services is out-of-date and the user can be prompted to update it).
      • Catches GooglePlayServicesNotAvailableException (e.g., when the device lacks GMS entirely, requiring a fallback).
  2. Static Analysis Artifacts (run.sh & output.txt):

    • Provides a run.sh script utilizing standard grep to simulate how a security tester (or SAST tool) would identify the secure implementation within the codebase.
    • Includes the expected output.txt verification file to ensure CI/CD testing properly validates the script's output against the demo code.
  3. MASTG-DEMO-0159.md:

    • The official MASTG demo write-up following the standard frontmatter format. It explains the vulnerability context, links the code snippets, and details how a tester would execute the static analysis to verify compliance with MASWE-0027.

All code has been written cleanly and adheres strictly to the standard Android developer guidelines for network security.


AI Tool Disclosure

Check exactly one option.

  • This contribution does not include AI-generated content.
  • This contribution includes AI-generated content.

If AI tools were used to generate or substantially modify code or text, complete the following.

  • AI tools used:
  • Models and versions:
  • Prompt summary:
  • Your mobile security expertise level:

For first-time contributors using AI tools.

  • Provide an export of the AI chat or session, for example a shared link or PDF attachment.
  • Ensure the commit history shows an initial commit with AI-generated content followed by commits that demonstrate review, correction, and improvement.

Contributor Checklist

  • I have read and understood the contributing guidelines.
  • I followed the project style guide.
  • I validated the technical correctness of my changes and understand the topic.
  • This PR adds clear value and is not spam or low-effort content.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The sample cannot build or run with the base app as submitted, and the static-analysis workflow is not reproducible.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds an Android demo for MASTG-TEST-0295, illustrating insecure and secure GMS Security Provider usage.

Changes:

  • Adds Kotlin sample implementations.
  • Adds static-analysis script and expected output.
  • Adds demo documentation and test metadata.
File summaries
File Description
MastgTest.kt Provider update examples
run.sh Static-analysis command
output.txt Expected analysis output
MASTG-DEMO-0159.md Demo instructions and evaluation
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 7
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@@ -0,0 +1,46 @@
package sg.vp.owasp_mobile.OMTG_Android
Comment on lines +4 to +6
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import com.google.android.gms.security.ProviderInstaller

The following sample code demonstrates how an app might establish a network connection without ensuring the GMS Security Provider is up to date, leaving it vulnerable to known SSL/TLS vulnerabilities on older Android devices. It also provides a secure implementation using `ProviderInstaller.installIfNeeded` to hot-patch the security provider.

{{ MastgTest.kt }}
Comment on lines +36 to +38
} catch (e: GooglePlayServicesRepairableException) {
// prompt user to repair/update play services
Log.e(TAG, "Play Services needs repair: ${e.message}")
@@ -0,0 +1 @@
grep -n "ProviderInstaller.installIfNeeded" MastgTest.kt
Comment on lines +2 to +6
title: GMS Security Provider Not Updated
platform: android
id: MASTG-DEMO-0159
test: MASTG-TEST-0295
code: [kotlin]
class MastgTest {
private val TAG = "MastgTest"

// insecure: not updating the GMS security provider
@Aspirant200715

Copy link
Copy Markdown
Author

Title: Update MASTG-DEMO-0159: Fix Compilation, Add Reversed Artifact, and Improve Static Analysis

Description: This PR addresses several issues in MASTG-DEMO-0159 to ensure the demo compiles correctly, properly handles Play Services resolution flows, and meets the standards for static-analysis demonstrations.

Changes Included:

Fixed App Compilation:
Updated MastgTest.kt to use the correct org.owasp.mastestapp package.
Added the expected MastgTest(context) constructor and the mastgTest() entry point to integrate correctly with the base app.
Added build.gradle.kts.libs to inject the missing com.google.android.gms:play-services-base dependency.
Implemented Resolution Flow: Updated secureNetworkCall() to explicitly trigger the repair prompt using GoogleApiAvailability.getInstance().showErrorNotification(...) when GooglePlayServicesRepairableException is caught, creating a proper caller-visible blocked state.
Added Decompiled Artifact: Added MastgTest_reversed.java to represent the reverse-engineered code, ensuring the documented static-analysis steps can be accurately reproduced.
Upgraded Static Analysis: Replaced the basic grep script in run.sh with a comprehensive Semgrep rule (rule.yml). The rule accurately reports relevant call sites for both ProviderInstaller usage and HttpsURLConnection instantiations. Updated output.txt to match.
Updated Documentation: Added the required // SUMMARY: comment to the Kotlin source and appended validation metadata (Platform, IDE, and Device info) to the bottom of MASTG-DEMO-0159.md for reproducibility.

@cpholguera

Copy link
Copy Markdown
Collaborator

Hi @Aspirant200715, unfortunately, your PR does not follow the writing guidelines, even though you have confirmed that you have read them. Please read them carefully before proceeding, pushing one commit per issue that you notice. This "one commit per change" approach is required of first-time contributors. It is unfortunately not allowed to make changes in bulk with one commit.

https://mas.owasp.org/contributing/writing-content/

I will give you two hints, but there are many more violations. IDs aren't compliant and there's something essentially wrong with the rule. You should be able to identify the other violations by reading the guidelines and committing fixes individually.

Also, one of our internal AI detectors has flagged your PR. Please disclose any AI-generated content in the relevant section of the PR description before proceeding.

Thank you!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add demo for MASTG-TEST-0295 (GMS Security Provider Not Updated)

3 participants