Skip to content

Latest commit

 

History

History
98 lines (79 loc) · 6.91 KB

File metadata and controls

98 lines (79 loc) · 6.91 KB

Mitigation Strategies Analysis for codermjlee/mjextension

  1. Identify Sensitive Properties: Review each model class (e.g., User, Product, Order) and identify properties that should not be directly populated from external JSON via MJExtension. These might include:

    • Internal IDs (e.g., database primary keys).
    • Security-related properties (e.g., password hashes, API keys).
    • Properties that are calculated or derived from other data.
    • Properties that control internal application state.
  2. Use mj_replacedKeyFromPropertyName:

    • For properties that should be populated from JSON, but where the JSON key name differs from the property name, use mj_replacedKeyFromPropertyName (or the Swift equivalent) to define the mapping. Example (Objective-C):
      + (NSDictionary *)mj_replacedKeyFromPropertyName {
          return @{
              @"userName" : @"username", // Maps JSON key "username" to property "userName"
              @"userEmail" : @"email"   // Maps JSON key "email" to property "userEmail"
          };
      }
    • This also acts as a whitelist: only JSON keys listed in this mapping will be considered by MJExtension.
  3. Use mj_ignoredPropertyNames:

    • For properties that should never be populated from JSON by MJExtension, use mj_ignoredPropertyNames (or the Swift equivalent) to explicitly exclude them. Example (Objective-C):
      + (NSArray *)mj_ignoredPropertyNames {
          return @[@"internalID", @"passwordHash", @"isAdmin"];
      }
  4. Review KVC usage with MJExtension:

    • Ensure that MJExtension, through its use of Key-Value Coding, is not exposing any unintended properties or methods. This requires careful review of how MJExtension interacts with your model objects.

    Threats Mitigated: * Mass Assignment: (Severity: High) - Prevents attackers from injecting values into unintended properties by providing extra keys in the JSON payload that MJExtension would otherwise process. * Over-Posting: (Severity: High) - Similar to mass assignment, prevents attackers from setting properties they shouldn't have access to via MJExtension. * Data Leakage (via KVC with MJExtension): (Severity: Medium to High) - Prevents unintended exposure of properties or methods through MJExtension's use of Key-Value Coding.

    Impact: * Mass Assignment/Over-Posting: Risk reduced significantly (90-95%) when mj_ignoredPropertyNames and mj_replacedKeyFromPropertyName are used correctly with MJExtension. * Data Leakage (via KVC): Risk reduced significantly (80-90%) with careful review and configuration of how MJExtension interacts with KVC.

    Currently Implemented: * mj_replacedKeyFromPropertyName is used in the User model to map a few keys.

    Missing Implementation: * mj_ignoredPropertyNames is not used in any model class. This is a critical missing piece for preventing mass assignment via MJExtension. * mj_replacedKeyFromPropertyName is not consistently used across all models; some models rely on direct key-to-property mapping, which is less secure with MJExtension. * A comprehensive review of KVC usage with MJExtension hasn't been performed.

  1. Identify Nested Structures: Identify any model properties that represent nested objects or arrays of objects that MJExtension will process.

  2. Use mj_objectClassInArray:

    • For properties that represent arrays of objects, and are processed by MJExtension, use mj_objectClassInArray (or the Swift equivalent) to specify the expected class of the objects within the array. Example (Objective-C):
      + (NSDictionary *)mj_objectClassInArray {
          return @{
              @"orders" : @"Order" // Specifies that the "orders" array contains "Order" objects
          };
      }
    • This provides type safety within MJExtension and helps prevent injection of unexpected object types.

    Threats Mitigated: * Type Confusion in Collections (within MJExtension): (Severity: Medium) - Ensures that arrays processed by MJExtension contain objects of the expected type, preventing logic errors or crashes that could arise from MJExtension passing incorrect types to your code.

    Impact: * Type Confusion in Collections: Risk reduced significantly (80-90%) with mj_objectClassInArray used correctly with MJExtension.

    Currently Implemented: * mj_objectClassInArray is used in a few places.

    Missing Implementation: * mj_objectClassInArray is not consistently used across all models with array properties that are handled by MJExtension.

Mitigation Strategy: Regular Updates of MJExtension

  1. Use a Dependency Manager: Use a dependency management tool (CocoaPods for Objective-C, Swift Package Manager for Swift) to manage the MJExtension library.

  2. Regularly Update:

    • Configure your dependency manager to check for updates regularly (e.g., daily or weekly).
    • Use commands like pod update (CocoaPods) or swift package update (Swift Package Manager) to update to the latest versions of MJExtension.
    • Test your application thoroughly after updating MJExtension to ensure that no regressions have been introduced.
  3. Monitor Security Advisories:

    • Subscribe to security advisories or mailing lists related to Objective-C/Swift development and common libraries.
    • Monitor the GitHub repository for MJExtension for any reported security issues.
    • If a vulnerability is discovered in MJExtension, update to a patched version as soon as possible.

    Threats Mitigated: * Known Vulnerabilities in MJExtension: (Severity: Variable, depends on the vulnerability) - Protects against any security flaws that may be discovered and fixed in the MJExtension library itself.

    Impact: * Known Vulnerabilities: Risk reduced significantly (dependent on timely updates). The faster you update MJExtension, the lower the risk.

    Currently Implemented: * CocoaPods is used to manage dependencies, including MJExtension.

    Missing Implementation: * Regular, automated updates of MJExtension are not configured. Updates are performed manually and infrequently. * There is no active monitoring of security advisories specifically for MJExtension.