Skip to content

Commit

Permalink
Protect jsonl file access
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Mar 25, 2024
1 parent 92b9cb6 commit 9abe793
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -46,6 +46,7 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the

* (klein0r) Fixed httpGet/httpPost issue when using without options
* (klein0r) Updated integration testing
* (klein0r) Protect jsonl file access

### 7.10.1 (2024-03-22)

Expand Down
8 changes: 5 additions & 3 deletions lib/protectFs.js
@@ -1,9 +1,11 @@
const nodeFS = require('fs');
const path = require('path');
const nodeFS = require('node:fs');
const path = require('node:path');

const ProtectFs = function (log) {
function checkObjectsJson(file) {
if (path.normalize(file).replace(/\\/g, '/').includes('-data/objects.json')) {
const filePath = path.normalize(file).replace(/\\/g, '/');

if (filePath.includes('-data/objects.json') || filePath.includes('-data/objects.jsonl')) {
if (log) {
log.error(`May not read ${file}`);
} else {
Expand Down
4 changes: 4 additions & 0 deletions lib/sandbox.js
Expand Up @@ -520,6 +520,10 @@ function sandBox(script, name, verbose, debug, context) {
verbose,
exports: {}, // Polyfill for the export object in TypeScript modules
require: function (md) {
if (typeof md === 'string' && md.startsWith('node:')) {
md = md.replace(/^node:/, '');
}

if (mods[md]) {
return mods[md];
} else {
Expand Down
2 changes: 0 additions & 2 deletions test/testFunctions.js
Expand Up @@ -401,7 +401,6 @@ describe.only('Test JS', function () {
});
});

/*
it('Test JS: open objects.json file must not work', function (done) {
this.timeout(20000);
// add script
Expand Down Expand Up @@ -457,7 +456,6 @@ describe.only('Test JS', function () {
expect(err).to.be.not.ok;
});
});
*/

it('Test JS: write objects.json not in data directory must work', function (done) {
this.timeout(3000);
Expand Down

0 comments on commit 9abe793

Please sign in to comment.