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
6 changes: 6 additions & 0 deletions packages/ruleset/src/utils/merge-allof-schema-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const { isObject, mergeWith } = require('lodash');
// Takes a schema, and if an allOf field is provided,
// merges all allOf schema properties to create one schema
function mergeAllOfSchemaProperties(schema) {
// Type guard: reject non-object input before applying 'in' operator
// This prevents TypeError when schema is a string (e.g., resolved file contents)
if (typeof schema !== 'object' || schema === null) {
return schema;
}

// Bail out immediately if 'schema' has no "allOf" field.
if (!('allOf' in schema)) {
return schema;
Expand Down
18 changes: 18 additions & 0 deletions packages/ruleset/test/utils/merge-allof-schema-properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,22 @@ describe('Utility function: mergeAllOfSchemaProperties()', () => {

expect(mergeAllOfSchemaProperties(schema)).toStrictEqual(expectedResult);
});

it('should safely handle non-object input (security: CWE-209)', async () => {
// Test with string input (simulates resolved file contents)
const stringInput = 'random_string_input';
expect(mergeAllOfSchemaProperties(stringInput)).toBe(stringInput);

// Test with null input
expect(mergeAllOfSchemaProperties(null)).toBe(null);

// Test with undefined input
expect(mergeAllOfSchemaProperties(undefined)).toBe(undefined);

// Test with number input
expect(mergeAllOfSchemaProperties(42)).toBe(42);

// Test with boolean input
expect(mergeAllOfSchemaProperties(true)).toBe(true);
});
});
Loading