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

fix: Improve ParseObject conformance to Hashable #176

Merged
merged 7 commits into from
Jul 13, 2024
Merged

Conversation

cbaker6
Copy link
Member

@cbaker6 cbaker6 commented Jul 13, 2024

New Pull Request Checklist

Issue Description

ParseObjects are using a custom hashing method that depended on objectId, createdAt, and updatedAt to determine if a hash was equal. This was a fairly weak implementation and only protected against values provided from the server. If a property on a ParseObject that wasn't objectId, createdAt, and updatedAt was changed locally, it would still hash to the same value.

For ParseFile, the type currently uses a custom function for Equatable.

Approach

Remove all custom hashing methods for ParseObjects and use the compiler level hasher which will hash all properties on an ParseObject assuming all of those objects are Hashable (which they should be). This moves in the direction of guaranteeing that collision attacks won't be possible (see discussion for details).

If a developer decides to add their own implementation of the hashing function they are doing so at their own risk and risking collision attacks. In addition, if their ParseObjects are used in SwiftUI views they may see unexpected behavior as SwiftUI heavily depends on Identifiable, Hashable, and Equatable to determine when a view should be updated.

For ParseFile, conforming to Equatable is improved by checking all properties are equal.

TODOs before merging

  • Add tests
  • Add entry to changelog

Copy link

codecov bot commented Jul 13, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.26%. Comparing base (b3e84a2) to head (3ac52ed).

Files Patch % Lines
Sources/ParseSwift/Types/ParseFile.swift 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #176      +/-   ##
==========================================
+ Coverage   91.09%   91.26%   +0.16%     
==========================================
  Files         178      178              
  Lines       12050    12073      +23     
==========================================
+ Hits        10977    11018      +41     
+ Misses       1073     1055      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cbaker6 cbaker6 merged commit 173e7d8 into main Jul 13, 2024
14 checks passed
@cbaker6 cbaker6 deleted the improveHashable branch July 13, 2024 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant