Skip to content

Latest commit

 

History

History
196 lines (159 loc) · 14.4 KB

File metadata and controls

196 lines (159 loc) · 14.4 KB

Mitigation Strategies Analysis for parse-community/parse-server

Description:

  1. Planning Phase: Before writing any code, define all data classes and their fields within your Parse Server schema. For each class and field, determine which user roles (or individual users) require access. Document these requirements.
  2. Implementation: Use the Parse Server dashboard (or the REST API/SDK) to configure CLPs for each class. Begin with no access granted to any role or user. Incrementally grant specific permissions (get, find, create, update, delete) to the appropriate roles/users.
  3. Field-Level Permissions: For sensitive fields, use FLPs to restrict access further. For example, a User class might have a passwordResetToken field only accessible to the user themselves and administrators.
  4. Role-Based Access: Create Parse Roles (e.g., "Admin," "Editor," "User"). Assign users to these roles. Configure CLPs and FLPs to grant permissions to roles, not individual users (except in rare, justified cases).
  5. Testing: Create test users within Parse Server, assigning them different roles. For each test user, attempt all CRUD operations on various classes and fields. Verify access is granted/denied as expected, including negative tests.
  6. Regular Audits: Schedule regular audits (e.g., monthly) of CLPs and FLPs within Parse Server. Review permissions and ensure they align with the principle of least privilege.
  7. Master Key Restriction: Avoid using the master key (useMasterKey: true or equivalent) in client-side code at all costs. Use it sparingly in Cloud Code, and only when absolutely necessary and documented.
  • Threats Mitigated:

    • Unauthorized Data Access (High Severity): Prevents users from accessing data they shouldn't see within Parse Server.
    • Unauthorized Data Modification (High Severity): Prevents unauthorized changes to data stored in Parse Server.
    • Unauthorized Data Deletion (High Severity): Prevents unauthorized deletion of data within Parse Server.
    • Data Enumeration (Medium Severity): Makes it harder to discover the database structure by probing for accessible data through Parse Server's API.
    • Privilege Escalation (High Severity): Prevents a user from gaining access to data/functionality intended for higher-privileged users within the Parse Server context.
  • Impact:

    • Unauthorized Data Access: Risk reduced significantly (80-95%). This is the primary defense within Parse Server.
    • Unauthorized Data Modification: Risk reduced significantly (80-95%).
    • Unauthorized Data Deletion: Risk reduced significantly (80-95%).
    • Data Enumeration: Risk reduced moderately (40-60%).
    • Privilege Escalation: Risk reduced significantly (80-95%).
  • Currently Implemented:

    • Basic CLPs are implemented for User and Product classes, granting read to authenticated users, create/update/delete to administrators.
    • Roles ("Admin," "User") are defined.
    • Master key is not used in client-side code.
  • Missing Implementation:

    • FLPs are not implemented. Sensitive fields in User (e.g., email) are accessible to all authenticated users.
    • No regular audit schedule.
    • Comprehensive testing of CLPs with different roles is incomplete.
    • No CLPs/FLPs for other classes (e.g., Order, Payment).

Mitigation Strategy: Secure Cloud Code Development

Description:

  1. Input Validation: In every Cloud Code function, validate all input parameters. Check types, lengths, formats, and allowed values. Use a validation library.
  2. Sanitization: Sanitize any input used in database queries within Cloud Code, especially when constructing queries dynamically. Use parameterized queries (provided by the Parse SDK) to prevent NoSQL injection.
  3. Least Privilege (Cloud Code): Avoid Parse.Cloud.useMasterKey() unless absolutely necessary. If a function only needs to read data, use a regular user session with appropriate CLPs.
  4. Error Handling: Implement robust error handling in Cloud Code. Catch exceptions and return generic error messages to the client. Log detailed errors securely on the Parse Server for debugging.
  5. Code Review: Require code reviews for all Cloud Code, focusing on security.
  6. Dependency Management: Regularly update Cloud Code dependencies (using npm update). Use npm audit to address vulnerabilities.
  7. Rate Limiting: Implement rate limiting for Cloud Code functions, especially those performing expensive operations or interacting with external services. Use a library like express-rate-limit (if using Express with Parse Server).
  8. Avoid Sensitive Operations in beforeFind: Do not rely solely on beforeFind for critical security, as it can be bypassed with the master key. Use beforeSave and other triggers, combined with CLPs/FLPs, for robust security.
  • Threats Mitigated:

    • NoSQL Injection (High Severity): Prevents injecting malicious code into database queries executed by Cloud Code.
    • Cross-Site Scripting (XSS) (Medium Severity): If Cloud Code generates HTML or interacts with the client, input validation and sanitization help.
    • Denial of Service (DoS) (Medium Severity): Rate limiting prevents overwhelming the Parse Server with Cloud Code requests.
    • Business Logic Errors (Variable Severity): Input validation and error handling prevent unexpected behavior.
    • Information Disclosure (Medium Severity): Proper error handling prevents leaking sensitive information from Parse Server.
    • Bypassing CLPs/FLPs (High Severity): Careful use of the master key and adherence to least privilege within Cloud Code prevents unintended circumvention of access controls.
  • Impact:

    • NoSQL Injection: Risk reduced significantly (90-95%).
    • XSS: Risk reduced moderately (50-70%).
    • DoS: Risk reduced significantly (70-80%).
    • Business Logic Errors: Risk reduced moderately (40-60%).
    • Information Disclosure: Risk reduced significantly (80-90%).
    • Bypassing CLPs/FLPs: Risk reduced significantly (80-90%).
  • Currently Implemented:

    • Basic input validation in some Cloud Code functions, but not consistent.
    • Parameterized queries are used in most cases.
  • Missing Implementation:

    • No consistent validation library.
    • No formal code review process.
    • No rate limiting.
    • Dependency updates are not regular.
    • Inconsistent error handling; some functions may expose details.
    • Parse.Cloud.useMasterKey() is used where it might not be necessary.
    • No checks in beforeSave and afterSave triggers.
    • Sensitive operations in beforeFind.

Mitigation Strategy: Controlled Live Queries

Description:

  1. Restrictive Queries: Guide developers to create Live Query subscriptions that are as specific as possible. Avoid broad queries.
  2. Subscription Limits: Implement server-side limits (using Cloud Code and a database class) on the number of Live Query subscriptions per user/IP address.
  3. Authentication: Require authentication for all Live Query subscriptions. Do not allow anonymous subscriptions without strong justification.
  4. Monitoring: Use Parse Server's monitoring tools (or custom logging) to track Live Query usage.
  5. Efficient Queries: Ensure database indexes are optimized for queries used in Live Query subscriptions.
  6. Controlled afterSave and afterDelete: Review afterSave and afterDelete triggers to ensure they don't generate unnecessary updates that trigger excessive Live Query notifications. Use conditional logic within these triggers.
  • Threats Mitigated:

    • Denial of Service (DoS) (Medium Severity): Prevents overwhelming the Parse Server with Live Query subscriptions.
    • Resource Exhaustion (Medium Severity): Limits Parse Server resources consumed by Live Queries.
    • Information Disclosure (Low Severity): Authentication prevents unauthorized users from subscribing to updates through Parse Server.
  • Impact:

    • DoS: Risk reduced significantly (70-80%).
    • Resource Exhaustion: Risk reduced significantly (70-80%).
    • Information Disclosure: Risk reduced significantly (80-90%).
  • Currently Implemented:

    • Authentication is required for Live Queries.
  • Missing Implementation:

    • No subscription limits.
    • No active monitoring.
    • No guidance for efficient subscriptions.
    • No review of afterSave and afterDelete triggers.

Description:

  1. File Type Validation: Use server-side Cloud Code (with a library like file-type) to determine the actual file type. Do not rely on client-provided data.
  2. File Size Limits: Configure Parse Server to enforce maximum file size limits.
  3. File Name Sanitization: In Cloud Code, generate unique, random file names. Do not use the client-provided name. Sanitize the original name to remove dangerous characters.
  4. Secure File Storage Adapter: Use a secure adapter (S3, GCS, etc.) and configure it properly through Parse Server's configuration.
  5. Virus Scanning (via Cloud Code): Integrate virus scanning into the file upload process using Cloud Code and an external API.
  • Threats Mitigated:

    • Malware Upload (High Severity): Prevents uploading malicious files to Parse Server's storage.
    • Directory Traversal (High Severity): File name sanitization prevents accessing/overwriting files outside the intended directory within the storage managed by Parse Server.
    • Cross-Site Scripting (XSS) (Medium Severity): File type validation helps prevent uploading files that could cause XSS.
    • Denial of Service (DoS) (Medium Severity): File size limits prevent consuming excessive Parse Server resources.
  • Impact:

    • Malware Upload: Risk reduced significantly (90-95%).
    • Directory Traversal: Risk reduced significantly (95-99%).
    • XSS: Risk reduced moderately (50-70%).
    • DoS: Risk reduced significantly (70-80%).
  • Currently Implemented:

    • Files are stored using the S3 adapter (configured through Parse Server).
    • Basic file size limits are configured in Parse Server.
  • Missing Implementation:

    • No server-side file type validation (in Cloud Code).
    • No file name sanitization; original names are used.
    • No virus scanning (via Cloud Code).

Description:

  1. HTTPS Enforcement: Ensure Parse Server is configured to only accept HTTPS connections.
  2. Session Expiration: Configure appropriate session expiration times in Parse Server's settings.
  3. Session Token Strength: Verify Parse Server uses strong, random session tokens (usually the default, but check configuration).
  4. Logout Functionality: Provide a clear "logout" function (which uses Parse Server's logout mechanism).
  5. "Logout from All Devices" (Cloud Code): Implement a feature to revoke all active sessions (requires custom Cloud Code interacting with Parse Server's _Session class).
  6. Session Token Rotation (Advanced, Cloud Code): Consider implementing session token rotation after significant actions (requires custom Cloud Code).
  7. Limit Session Data: Avoid storing sensitive data directly in the Parse Server _Session object.
  • Threats Mitigated:

    • Session Hijacking (High Severity): Prevents stealing session tokens and impersonating users within Parse Server.
    • Session Fixation (Medium Severity): Session token rotation (if implemented) helps.
    • Man-in-the-Middle (MitM) Attacks (High Severity): HTTPS enforcement prevents MitM attacks that could intercept session tokens communicated with Parse Server.
  • Impact:

    • Session Hijacking: Risk reduced significantly (80-90%).
    • Session Fixation: Risk reduced moderately (50-70%).
    • MitM Attacks: Risk reduced significantly (90-95%).
  • Currently Implemented:

    • HTTPS is enforced.
    • Session expiration is configured.
    • Basic logout functionality.
  • Missing Implementation:

    • No "logout from all devices".
    • No session token rotation.
    • Session expiration timeout could be shorter.

Description: (If using Parse Server's GraphQL API)

  1. Query Depth Limiting: Use a library (e.g., graphql-depth-limit) to limit query depth.
  2. Query Cost Analysis: Implement query cost analysis (e.g., graphql-cost-analysis).
  3. Introspection Control: Disable/restrict introspection in production.
  4. Rate Limiting (GraphQL-Specific): Implement rate limiting for GraphQL queries.
  5. Validation: Ensure queries and input are validated against the schema.
  6. Authentication and Authorization: Integrate with Parse Server's authentication (user sessions) and CLPs/FLPs to control access through GraphQL.
  • Threats Mitigated:

    • Denial of Service (DoS) (Medium Severity): Prevents overwhelming Parse Server with expensive GraphQL queries.
    • Information Disclosure (Medium Severity): Introspection control prevents discovering the schema easily.
    • Unauthorized Data Access (High Severity): Integration with Parse Server's authentication and authorization prevents unauthorized access.
  • Impact:

    • DoS: Risk reduced significantly (70-80%).
    • Information Disclosure: Risk reduced significantly (80-90%).
    • Unauthorized Data Access: Risk reduced significantly (80-90%).
  • Currently Implemented:

    • None (GraphQL API is not currently used).
  • Missing Implementation:

    • All (implement before enabling GraphQL).