Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "jest"],
"env": {
"node": true
"node": true,
"jest/globals": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"overrides": [
{
"files": ["*.js", "*.ts"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unused-vars": "off"
}
},
{
"files": ["*.md"],
"parser": "eslint-plugin-markdownlint/parser",
Expand Down
4 changes: 1 addition & 3 deletions examples/bug-detectors/command-injection/custom-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* Examples showcasing the custom hooks API
*/

/* eslint-disable @typescript-eslint/no-var-requires,@typescript-eslint/no-unused-vars */

const { registerReplaceHook } = require("@jazzer.js/hooking");
const { reportFinding } = require("@jazzer.js/bug-detectors");
const { guideTowardsEquality } = require("@jazzer.js/fuzzer");
Expand All @@ -29,7 +27,7 @@ registerReplaceHook(
"execSync",
"child_process",
false,
(thisPtr, params, hookId, origFn) => {
(thisPtr, params, hookId) => {
if (params === undefined || params.length === 0) {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions examples/bug-detectors/command-injection/fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { FuzzedDataProvider } = require("@jazzer.js/core");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const root = require("global-modules-path");

module.exports.fuzz = function (data) {
const provider = new FuzzedDataProvider(data);
const str1 = provider.consumeString(provider.consumeIntegralInRange(1, 20));
Expand Down
31 changes: 13 additions & 18 deletions examples/bug-detectors/path-traversal/fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const JSZip = require("jszip");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require("path");

/**
Expand All @@ -26,20 +24,17 @@ const path = require("path");
module.exports.fuzz = function (data) {
// Parse the buffer into a JSZip object. The buffer might have been obtained from an http-request.
// See https://stuk.github.io/jszip/documentation/howto/read_zip.html for some examples.
return (
JSZip.loadAsync(data)
.then((zip) => {
for (const file in zip.files) {
// We might want to extract the file from the zip archive and write it to disk.
// The loadAsync function should have sanitized the path already.
// Here we only construct the absolute path and trigger the path traversal bug.
// This issue was fixed in jszip 3.8.0.
path.join(__dirname, file);
}
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch(() => {
/* ignore broken zip files */
})
);
return JSZip.loadAsync(data)
.then((zip) => {
for (const file in zip.files) {
// We might want to extract the file from the zip archive and write it to disk.
// The loadAsync function should have sanitized the path already.
// Here we only construct the absolute path and trigger the path traversal bug.
// This issue was fixed in jszip 3.8.0.
path.join(__dirname, file);
}
})
.catch(() => {
/* ignore broken zip files */
});
};
12 changes: 5 additions & 7 deletions examples/custom-hooks/custom-hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// noinspection JSUnusedLocalSymbols
/* eslint-disable @typescript-eslint/no-var-requires,@typescript-eslint/no-unused-vars */

/*
* Copyright 2022 Code Intelligence GmbH
*
Expand Down Expand Up @@ -32,7 +29,7 @@ registerReplaceHook(
"JpegImage.jpegImage.constructor.prototype.copyToImageData.copyToImageData",
"jpeg-js",
false,
(thisPtr, params, hookId, origFn) => {
(thisPtr, params) => {
if (params[0].data[0] === 0) {
// we are only interested in image frames in which data[0] equals zero
throw Error(
Expand Down Expand Up @@ -101,7 +98,7 @@ registerBeforeHook(
"JpegImage.jpegImage.constructor.prototype.parse.parse.readDataBlock",
"jpeg-js",
false,
(thisPtr, params, hookId) => {
() => {
console.log(
`[jpeg-js] [before] Called hooked function before calling resetMaxMemoryUsage()`,
);
Expand Down Expand Up @@ -131,6 +128,7 @@ registerReplaceHook(
"JpegImage.jpegImage.constructor.prototype.parse.parse.NonExistingFunc",
"jpeg-js",
false,
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {},
() => {
/* empty */
},
);
1 change: 0 additions & 1 deletion examples/custom-hooks/fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/jpeg/fuzz.js
// The original code is available under the Apache License 2.0.

// eslint-disable-next-line @typescript-eslint/no-var-requires
const jpeg = require("jpeg-js");

/**
Expand Down
6 changes: 1 addition & 5 deletions examples/jest_integration/integration.fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

/* eslint no-undef: 0, no-constant-condition: 0, @typescript-eslint/no-var-requires:0 */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const target = require("./target.js");

describe("My describe", () => {
Expand Down Expand Up @@ -56,7 +53,7 @@ describe("My describe", () => {
// finding and shut down the whole process with exit code 70.
it.skip.fuzz("Sync timeout", () => {
// noinspection InfiniteLoopJS
while (true) {
for (;;) {
// Ignore
}
});
Expand All @@ -74,7 +71,6 @@ describe("My describe", () => {
// regression and fuzzing mode. libFuzzer shuts down the process after Jest
// received the error and displayed its result.
// Two parameters are required to execute the done callback branch.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
it.skip.fuzz("Done callback timeout", (ignore, ignore2) => {
// don't call done
});
Expand Down
2 changes: 0 additions & 2 deletions examples/jest_integration/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint no-undef: 0 */

describe("My describe", () => {
it("My normal Jest test", () => {
expect(1).toEqual(1);
Expand Down
4 changes: 0 additions & 4 deletions examples/jest_integration/worker.fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

/* eslint no-undef: 0 */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const target = require("./target");

const startupTeardownCalls = [];
Expand Down Expand Up @@ -59,7 +56,6 @@ describe("Hooks", () => {
let test = 0;
// Busy wait, do nothing
for (let i = 0; i < 1000; i++) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
test++;
}
addCallLog("My describe: afterEach");
Expand Down
3 changes: 0 additions & 3 deletions examples/jest_integration/workerGoldenReference.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint no-undef: 0 */

const startupTeardownCalls = [];

function addCallLog(uniqueId) {
Expand Down Expand Up @@ -60,7 +58,6 @@ describe("My describe", () => {
let test = 0;
// Busy wait, do nothing
for (let i = 0; i < 1000; i++) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
test++;
}
addCallLog("My describe: afterEach");
Expand Down
2 changes: 0 additions & 2 deletions examples/jest_typescript_integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint no-undef: 0 */

import * as target from "./target";

describe("My describe", () => {
Expand Down
1 change: 0 additions & 1 deletion examples/jpeg/fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/jpeg/fuzz.js
// The original code is available under the Apache License 2.0.

// eslint-disable-next-line @typescript-eslint/no-var-requires
const jpeg = require("jpeg-js");

/**
Expand Down
1 change: 0 additions & 1 deletion examples/jpeg_es6/fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/jpeg/fuzz.js
// The original code is available under the Apache License 2.0.

// eslint-disable-next-line @typescript-eslint/no-var-requires
import { decode } from "jpeg-js";

/**
Expand Down
1 change: 0 additions & 1 deletion examples/spectral/spectral-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const parsers = require("@stoplight/spectral-parsers");

/**
Expand Down
1 change: 0 additions & 1 deletion examples/xml/fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// https://gitlab.com/gitlab-org/security-products/analyzers/fuzzers/jsfuzz/-/blob/34a694a8c73bfe0895c4e24784ba5b6dfe964b94/examples/xml/fuzz.js
// The original code is available under the Apache License 2.0.

// eslint-disable-next-line @typescript-eslint/no-var-requires
const xml2js = require("xml2js");

/**
Expand Down
4 changes: 1 addition & 3 deletions fuzztests/FuzzedDataProvider.fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
* limitations under the License.
*/

/* eslint-disable no-undef, @typescript-eslint/no-var-requires */

const { FuzzedDataProvider, jazzer } = require("@jazzer.js/core");

describe("FuzzedDataProvider", () => {
// In this fuzz test we try to guide the fuzzer to use as many functions on
// FuzzedDataProvider as possible, before invoking a terminating one
// like consumeRemainingXY. Strange combinations of functions could produce a
// one off error.
// one-off error.
it.fuzz(
"consumes the provided input",
(data) => {
Expand Down
2 changes: 0 additions & 2 deletions fuzztests/core.fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint-disable no-undef, @typescript-eslint/no-var-requires */

const { ensureFilepath } = require("@jazzer.js/core");

const cwd = process.cwd();
Expand Down
2 changes: 0 additions & 2 deletions fuzztests/fuzzer.fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint-disable no-undef, @typescript-eslint/no-var-requires */

const { fuzzer } = require("@jazzer.js/fuzzer");
const { FuzzedDataProvider } = require("@jazzer.js/core");

Expand Down
2 changes: 0 additions & 2 deletions fuzztests/instrument.fuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

/* eslint-disable no-undef, @typescript-eslint/no-var-requires */

const { Instrumentor } = require("@jazzer.js/instrumentor");
const { FuzzedDataProvider } = require("@jazzer.js/core");

Expand Down
2 changes: 0 additions & 2 deletions fuzztests/runFuzzTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Helper script that searches for Jest fuzz tests in the current directory and
// executes them in new processes using the found fuzz test names.

/* eslint-disable @typescript-eslint/no-var-requires */

const fs = require("fs/promises");
const { spawn } = require("child_process");

Expand Down
1 change: 0 additions & 1 deletion packages/fuzzer/fuzzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

/* eslint no-empty-function: 0 */
import { fuzzer } from "./fuzzer";

describe("compare hooks", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooking/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

/* eslint @typescript-eslint/no-explicit-any: 0 */

export interface TrackedHook {
target: string;
pkg: string;
Expand Down Expand Up @@ -143,7 +145,6 @@ export function logHooks(hooks: Hook[]) {

export const hookTracker = new HookTracker();

/*eslint @typescript-eslint/no-explicit-any: 0 */
export enum HookType {
Before,
After,
Expand Down
37 changes: 25 additions & 12 deletions packages/hooking/manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
/*
* Copyright 2023 Code Intelligence GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { hookManager } from "./manager";
import { HookType } from "./hook";

/* eslint @typescript-eslint/no-empty-function: 0 */
/* eslint @typescript-eslint/ban-types: 0 */

describe("Hooks manager", () => {
describe("Matching hooks", () => {
it("should be valid when having a single REPLACE hook", () => {
Expand Down Expand Up @@ -100,18 +113,18 @@ function registerHook(
) {
switch (hookType) {
case HookType.Before:
hookManager.registerHook(HookType.Before, target, pkg, isAsync, () => {});
hookManager.registerHook(HookType.Before, target, pkg, isAsync, () => {
/* empty */
});
break;
case HookType.Replace:
hookManager.registerHook(
HookType.Replace,
target,
pkg,
isAsync,
() => {},
);
hookManager.registerHook(HookType.Replace, target, pkg, isAsync, () => {
/* empty */
});
break;
case HookType.After:
hookManager.registerHook(HookType.After, target, pkg, isAsync, () => {});
hookManager.registerHook(HookType.After, target, pkg, isAsync, () => {
/* empty */
});
}
}
Loading