Skip to content

Proof of Concept Insights - Attempt to assign a readonly property - this.call #8

@bentobox19

Description

@bentobox19

PoC

https://github.com/LavaMoat/docs/blob/main/react-native-and-ses-lockdown.md

Discussion

Sample Error

TypeError: Attempted to assign to readonly property.

We find the cause of this error at node_modules/web3-core-methods/src/index.js

var Method = function Method(options) {

    if (!options.call || !options.name) {
        throw new Error('When creating a method you need to provide at least the "name" and "call" property.');
    }

    this.name = options.name;
    this.call = options.call;
    this.params = options.params || 0;

Now, as Function.protoype.call was frozen, this.call = options.call throws

TypeError: Attempted to assign to readonly property.

Solution Proposed

The Object.defineProperty workaround

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty

Replace this

this.call = options.call;

By this

Object.defineProperty(this, 'call', {
  value: option.call
});

Items of Actions

  • Make sure we are extracting the correct functionality of the library.
  • If this works properly, understand why this works.
  • Send a PR to the package's repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions