Skip to content

Avoid prototype-polluting assignments in local data providers#11227

Merged
ThieryMichel merged 12 commits intomasterfrom
fix-local-data-provider-prototype-pollution
Apr 3, 2026
Merged

Avoid prototype-polluting assignments in local data providers#11227
ThieryMichel merged 12 commits intomasterfrom
fix-local-data-provider-prototype-pollution

Conversation

@WiXSL
Copy link
Copy Markdown
Collaborator

@WiXSL WiXSL commented Mar 31, 2026

Summary

  • Add tests on prototype ppollution prevention

Why

GitHub code scanning reports four Prototype-polluting assignment alerts:

These alerts are false positive since we check resource name on all resources
Added tests to on the check

Testing

  • yarn test-unit --runTestsByPath packages/ra-data-local-storage/src/index.spec.ts packages/ra-data-local-forage/src/index.spec.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses prototype-pollution risks reported by code scanning in the local data providers by routing resource collection writes through safer helpers and adding regression tests for safe collection creation and invalid resource keys.

Changes:

  • Replace dynamic data[resource] = [] and data[resource][index] = ... mutations with safer collection accessors (getResourceCollection, getOrCreateResourceCollection) and array mutation helpers.
  • Apply the same approach to both ra-data-local-storage and ra-data-local-forage providers for create/update/delete flows.
  • Add new unit tests covering safe creation of missing collections and rejection of unsafe resource keys.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
packages/ra-data-local-storage/src/index.ts Routes write operations through validated resource collections and avoids direct prototype-polluting assignments.
packages/ra-data-local-storage/src/index.spec.ts Adds regression tests for safe collection creation and unsafe resource key rejection.
packages/ra-data-local-forage/src/index.ts Mirrors the safer collection write approach for localForage-backed storage.
packages/ra-data-local-forage/src/index.spec.ts Adds regression tests for safe collection creation and unsafe resource key rejection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@ThieryMichel ThieryMichel left a comment

Choose a reason for hiding this comment

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

A simpler and more straightforward fix would be to check that resource === 'proto' and throw an error when it is.
Also add comment to explain the reason.
Need to see if this will content codeql though

@ThieryMichel ThieryMichel merged commit a93706d into master Apr 3, 2026
15 checks passed
@ThieryMichel ThieryMichel deleted the fix-local-data-provider-prototype-pollution branch April 3, 2026 14:01
@ThieryMichel ThieryMichel added this to the 5.14.6 milestone Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants