Skip to content

Commit

Permalink
fix: prevent prototype polution through keys and paths
Browse files Browse the repository at this point in the history
Closes #1111
  • Loading branch information
Skaiir committed Mar 27, 2024
1 parent de3fbe8 commit 4067378
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/form-js-editor/src/features/properties-panel/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ export function isValidDotPath(path) {
return /^\w+(\.\w+)*$/.test(path);
}

/**
* @param {string} path
*/
export function isProhibitedPath(path) {
const prohibitedSegments = [
'__proto__',
'prototype',
'constructor'
];

return path.split('.').some(segment => prohibitedSegments.includes(segment));
}

export const LABELED_NON_INPUTS = [
'button',
'group',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isString, get } from 'min-dash';

import { hasIntegerPathSegment, isValidDotPath } from '../Util';
import { hasIntegerPathSegment, isProhibitedPath, isValidDotPath } from '../Util';

import { useService } from '../hooks';

Expand Down Expand Up @@ -76,6 +76,10 @@ function Key(props) {
return 'Must not contain numerical path segments.';
}

if (isProhibitedPath(value)) {
return 'Must not be a prohibited path.';
}

const replacements = {
[ field.id ]: value.split('.')
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useService } from '../hooks';

import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';

import { isValidDotPath } from '../Util';
import { isProhibitedPath, isValidDotPath, hasIntegerPathSegment } from '../Util';
import { useCallback } from 'preact/hooks';


Expand Down Expand Up @@ -80,11 +80,15 @@ function Path(props) {
}

// Check for integer segments in the path
const hasIntegerPathSegment = value.split('.').some(segment => /^\d+$/.test(segment));
if (hasIntegerPathSegment) {
if (hasIntegerPathSegment(value)) {
return 'Must not contain numerical path segments.';
}

// Check for special prohibited paths
if (isProhibitedPath(value)) {
return 'Must not be a prohibited path.';
}

// Check for path collisions
const options = {
replacements: {
Expand Down

0 comments on commit 4067378

Please sign in to comment.