Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Risk - Backup Unencrypted [backup-unencrypted] #2541

Open
4 tasks
cpholguera opened this issue Feb 5, 2024 · 6 comments · May be fixed by #2604
Open
4 tasks

New Risk - Backup Unencrypted [backup-unencrypted] #2541

cpholguera opened this issue Feb 5, 2024 · 6 comments · May be fixed by #2604

Comments

@cpholguera
Copy link
Collaborator

cpholguera commented Feb 5, 2024

Description

Create a new risk for "Backup Unencrypted (MASVS-STORAGE-2)" using the following information:

The app may not encrypt sensitive data in backups, which may compromise data confidentiality.

Create "risks/MASVS-STORAGE/2-***-****/backup-unencrypted/risk.md" including the following content:

---
title: Backup Unencrypted
alias: backup-unencrypted
platform: [android]
profiles: [L2]
mappings:
  masvs-v1: [MSTG-STORAGE-8]
  masvs-v2: [MASVS-STORAGE-2, MASVS-PRIVACY-1]
  mastg-v1: [MASTG-TEST-0058, MASTG-TEST-0009]

---

## Overview

## Impact

## Modes of Introduction

## Mitigations

To complete the sections follow the guidelines from Writing MASTG Risks & Tests

Use at least the following references:

When creating the corresponding tests, use the following areas to guide you:

  • Backup Device Conditions clientSideEncryption and deviceToDeviceTransfer Not Checked (Android)

MASTG v1 Refactoring:

If the risk has a MASVS v1 ID, you can use it to search for related tests in the MASTG and use them as input to define your risks and associated tests.

Acceptance Criteria

  • The risk has been created in the correct directory (risks/MASVS-STORAGE/2-***-****/backup-unencrypted/risk.md)
  • The risk content follows the guidelines
  • At least one GitHub Issue has been created for the corresponding tests (derived from "Modes of Introduction")
  • The risk indicates the related MASTG v1 tests in its metadata.
@cpholguera
Copy link
Collaborator Author

@e-a-security

@e-a-security
Copy link
Collaborator

e-a-security commented Feb 25, 2024

First run-through:

Overview

Applications commonly store data for use, whether locally on the device, within external storage, or remotely in cloud storage. When stored data relates to sensitive information, such as a user's personal data or authentication keys and passwords, additional security measures can be applied to prevent the leaking of this sensitive data if the backup is accessed by someone other than the intended user.

Impact

An attacker with access to an application's backup file can retrieve any unencrypted data that the application has backed up. As a result, any sensitive data exposed can be used by the attacker in future attacks or be readily exploited.

Modes of Introduction

  • Default Settings: Mobile OSs may not encrypt backup data by default, risking sensitive data exposure.
  • Custom Solutions: Some developers' custom backup solutions may neglect proper data encryption.
  • Third-party Services: Integration with third-party backup services without ensuring encryption can lead to vulnerabilities.
  • Development Practices: Temporarily disabling encryption for debugging, then failing to re-enable it, leaves production backups unsecured.

Migration:

  • Encrypt Backup Data: Ensure all backup data is encrypted using strong encryption algorithms before it is stored or transmitted. For iOS, use the APIs that enforce encryption during iCloud backups. For Android, utilize the Backup Service API with encryption enabled for cloud backups.
  • Secure Backup Keys: Use the platform's keystore (iOS Keychain or Android Keystore) to securely store encryption keys. Never store keys within the backup data itself or in insecure locations.
  • Backup Access Controls: Implement strict access controls for backup data. Ensure that only authorized users and systems can access or restore from backups.

Additional Nodes

Prerequisites --> identify-sensitive-data
CVEs --> Off a couple google searches, found just this one so far, will locate more; I don't see many options based on some searching here: https://cve.mitre.org/cve/search_cve_list.html

Tests brainstorming:

@e-a-security
Copy link
Collaborator

e-a-security commented Apr 1, 2024

Complete. Just waiting to see best way to upload files / which branch / version we want these to go into.

Structure Overview

  • risk.md: Contains a detailed overview of the unencrypted backup risk, its impact, modes of introduction, and migration strategies.
  • android-backup-unencrypted-use: For Android applications using unencrypted backups.
    • rules: YAML files for static analysis checks.
    • example: Java and XML examples demonstrating risks and mitigation techniques.
  • ios-backup-unencrypted-use: For iOS applications at risk of including sensitive data in unencrypted backups.
    • rules: detect_sensitive_data_storage.yaml: A Semgrep rule to identify potential storage of sensitive data in ways that might be included in backups. Encourages review to ensure data is encrypted and properly excluded from backups.
    • example: SensitiveDataStorageExample.swift: Demonstrates handling of data in ways that could be included in unencrypted backups, along with techniques to exclude or encrypt such data properly.
    • run.sh: Script to facilitate running static analysis against the Swift example code, providing findings that highlight areas needing secure data handling attention.

Removing these 2:

Originally these show how secure encrypted backup is done which is the opposite of the unencrypted code - it feels redundant with the unencrypted code

  • android-backup-encrypted-use: For Android applications implementing encrypted backups.
    • rules: YAML files for static analysis to encourage encrypted backup configurations.
    • example: Examples showing how to configure encrypted backups in AndroidManifest.xml.
  • ios-backup-encrypted-use: For iOS applications ensuring sensitive data is excluded or encrypted in backups.
    • rules: Markdown guide for manual review guidelines on excluding sensitive data from backups.
    • example: Swift examples for programmatically excluding files from iCloud backups.

iOS Unencrypted Rules

Patterns of Concern

  • UserDefaults for Sensitive Data: Storing sensitive information, such as tokens or personal identifiers, in UserDefaults.
  • FileManager for Direct File Creation: Using FileManager to directly create files without encrypting the data first.
  • Loading Data with NSKeyedArchiver Without Secure Coding: Serializing objects using NSKeyedArchiver without requiring secure coding can lead to sensitive data being saved in an unencrypted form
  • Core Data Persistent Stores Without Encryption: Configuring Core Data without file encryption, which can result in the database being easily accessible and readable outside of the application's secure context.
  • Disabling File Protection: Explicitly setting file protection attributes to none, thereby disabling the built-in encryption iOS provides for file storage.

Android Unencrypted Rules

  • Unencrypted Android Backups: Detects when the allowBackup attribute is enabled, potentially leading to unencrypted data backups.
  • Cloud Backup of Sensitive Data: Flags potential inclusion of sensitive data in cloud backups without proper exclusion settings.
  • SharedPreferences Sensitive Data: Identifies usage of SharedPreferences to store sensitive data, which might not be encrypted by default.
  • Missing Encryption in Data Handling: Highlights instances where sensitive data might be handled without apparent encryption, indicating a potential risk.
  • External Storage Sensitive Data: Warns about writing sensitive data to external storage, which can be accessed by any app with the right permissions, without encrypting the data first.

e-a-security added a commit to e-a-security/owasp-mastg that referenced this issue Apr 14, 2024
@cpholguera
Copy link
Collaborator Author

@e-a-security could you please open the PR against our master branch? Thank you!

@e-a-security
Copy link
Collaborator

@cpholguera Gotcha, done here: #2604 Let me know if I should change anything else.
Thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants