lionleaf / lionleaf/dwitter

Valid code microservice/endpoint with V8 Virtual Machine

Open
#238 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
803
Forks
68
PR merge metrics
No merged PRs in 30d

Description

I've found some small bugs at the frontend when I try to run my own dweet, so I offer the following schema. We could create microservice or endpoint where will be created instance of V8's Virtual Machine with specified sandbox which is a canvas API stub.

So we could check valid our code or not, for example:

```
const isEqual = require('lodash.isequal')
const vm = require('vm');
const canvasStub = {
canvas: {
fillRect: function(){}
}
}

const sandbox = Object.assign({}, canvasStub)
vm.createContext(sandbox)

const code = "canvas.fillRect()"

try {
const result = vm.runInContext(code, sandbox, {
timeout: 1000
});
console.log('is code valid', isEqual(sandbox, canvasStub))
} catch (e) {
console.log('non valid code', e)
}
```

So if use will send `this.a = '1'` or `new XMLHttpRequest()` code will be not valid.
Also VM will have option for timeout that will protect against infinite loop in the code

In result if code is valid then we will create iframe with this user code

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files, tests, or entry points are named. Start by locating the existing frontend dweet execution flow and determine where a V8 VM-backed microservice or endpoint could fit. Done means the proposed sandbox validation handles the canvas stub, rejects the described mutations and XMLHttpRequest usage, enforces the timeout, and gates iframe creation on valid code.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.