Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest release #1451

Open
wants to merge 10,000 commits into
base: workers
Choose a base branch
from
Open

update to latest release #1451

wants to merge 10,000 commits into from

Conversation

npenin
Copy link
Owner

@npenin npenin commented Oct 2, 2024

No description provided.

Copy link

gitguardian bot commented Oct 2, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

catch (result)
{
if (typeof result !== 'undefined' && step.outputAs)
results[job.name][step.outputAs] = result

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1).

Copilot Autofix AI 4 months ago

To fix the prototype pollution issue, we should ensure that the keys used in the results object cannot be __proto__, constructor, or prototype. This can be achieved by either using a Map object or by explicitly checking and rejecting these keys.

The best way to fix this without changing existing functionality is to add a check to reject these keys. This approach is straightforward and does not require significant changes to the existing code structure.

Suggested changeset 1
packages/automate/src/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/automate/src/index.ts b/packages/automate/src/index.ts
--- a/packages/automate/src/index.ts
+++ b/packages/automate/src/index.ts
@@ -309,2 +309,5 @@
         let previousStepName: string = name + '#prerequisites';
+        if (job.name === '__proto__' || job.name === 'constructor' || job.name === 'prototype') {
+            throw new Error('Invalid job name: ' + job.name);
+        }
         results[job.name] = {};
EOF
@@ -309,2 +309,5 @@
let previousStepName: string = name + '#prerequisites';
if (job.name === '__proto__' || job.name === 'constructor' || job.name === 'prototype') {
throw new Error('Invalid job name: ' + job.name);
}
results[job.name] = {};
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
let interpolateString: RegExpExecArray;
let result = '';
let lastOffset = 0;
const regexp = /\{([A-Z][A-Z0-9]+)(?:#([A-Z][A-Z0-9]+)*)?\}/gi;

Check failure

Code scanning / CodeQL

Inefficient regular expression

This part of the regular expression may cause exponential backtracking on strings starting with '{{a0#a' and containing many repetitions of '0a'.

Copilot Autofix AI 3 months ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. Specifically, we can replace the [A-Z0-9]+ pattern with a more precise pattern that avoids ambiguity. One way to achieve this is to use a non-capturing group with a negated character class to ensure that each character is matched only once.

  • Modify the regular expression on line 154 to avoid exponential backtracking.
  • Replace [A-Z0-9]+ with (?:[A-Z0-9]+) to ensure that the pattern matches each character only once.
Suggested changeset 1
packages/aws-sdk/src/cli/generate-sdk.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/aws-sdk/src/cli/generate-sdk.ts b/packages/aws-sdk/src/cli/generate-sdk.ts
--- a/packages/aws-sdk/src/cli/generate-sdk.ts
+++ b/packages/aws-sdk/src/cli/generate-sdk.ts
@@ -153,3 +153,3 @@
             let lastOffset = 0;
-            const regexp = /\{([A-Z][A-Z0-9]+)(?:#([A-Z][A-Z0-9]+)*)?\}/gi;
+            const regexp = /\{([A-Z][A-Z0-9]*)(?:#([A-Z][A-Z0-9]*))?\}/gi;
             while (interpolateString = regexp.exec(obj))
EOF
@@ -153,3 +153,3 @@
let lastOffset = 0;
const regexp = /\{([A-Z][A-Z0-9]+)(?:#([A-Z][A-Z0-9]+)*)?\}/gi;
const regexp = /\{([A-Z][A-Z0-9]*)(?:#([A-Z][A-Z0-9]*))?\}/gi;
while (interpolateString = regexp.exec(obj))
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
}
}

let item = /^[\w0-9\$_]*\??/.exec(expression)[0];

Check warning

Code scanning / CodeQL

Overly permissive regular expression range

Suspicious character range that overlaps with \\w in the same character class.

Copilot Autofix AI 3 days ago

To fix the problem, we need to remove the redundant 0-9 from the character class in the regular expression. The \w character class already includes digits, so we can simplify the regular expression by removing 0-9.

  • In the file packages/core/src/parser/parser.ts, locate the regular expression on line 384.
  • Modify the regular expression to remove the redundant 0-9 from the character class.
  • Ensure that the functionality remains the same by keeping the rest of the regular expression intact.
Suggested changeset 1
packages/core/src/parser/parser.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/core/src/parser/parser.ts b/packages/core/src/parser/parser.ts
--- a/packages/core/src/parser/parser.ts
+++ b/packages/core/src/parser/parser.ts
@@ -383,3 +383,3 @@
 
-        let item = /^[\w0-9\$_]*\??/.exec(expression)[0];
+        let item = /^[\w\$_]*\??/.exec(expression)[0];
         const itemLength = item.length;
EOF
@@ -383,3 +383,3 @@

let item = /^[\w0-9\$_]*\??/.exec(expression)[0];
let item = /^[\w\$_]*\??/.exec(expression)[0];
const itemLength = item.length;
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

if (tag.event && tag.attributes.id)
{
result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${JSON.stringify(tag.attributes.id.value)}))})` });

Check warning

Code scanning / CodeQL

Improper code sanitization

Code construction depends on an [improperly sanitized value](1).

Copilot Autofix AI 3 months ago

To fix the problem, we need to ensure that any potentially dangerous characters in the tag.event keys and values are properly escaped before being inserted into the JavaScript code. We can achieve this by creating a function that escapes unsafe characters and using it to sanitize the tag.event keys and values.

  1. Create a function escapeUnsafeChars that escapes potentially dangerous characters.
  2. Use this function to sanitize the tag.event keys and values before inserting them into the JavaScript code.
Suggested changeset 1
packages/pages/src/dom-walker.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/pages/src/dom-walker.ts b/packages/pages/src/dom-walker.ts
--- a/packages/pages/src/dom-walker.ts
+++ b/packages/pages/src/dom-walker.ts
@@ -15,2 +15,21 @@
 
+const charMap = {
+    '<': '\\u003C',
+    '>' : '\\u003E',
+    '/': '\\u002F',
+    '\\': '\\\\',
+    '\b': '\\b',
+    '\f': '\\f',
+    '\n': '\\n',
+    '\r': '\\r',
+    '\t': '\\t',
+    '\0': '\\0',
+    '\u2028': '\\u2028',
+    '\u2029': '\\u2029'
+};
+
+function escapeUnsafeChars(str) {
+    return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, x => charMap[x])
+}
+
 class TagRefImpl<TTag extends string, T extends Tag<TTag> | TypedCustomTag<TTag, U>, U>
@@ -222,3 +241,3 @@
             {
-                result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${JSON.stringify(tag.attributes.id.value)}))})` });
+                result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${escapeUnsafeChars(JSON.stringify(e[0]))}, ${escapeUnsafeChars(e[1].toString())})`).join(';' + prefix)}})(document.getElementById(${escapeUnsafeChars(JSON.stringify(tag.attributes.id.value))}))})` });
             }
EOF
@@ -15,2 +15,21 @@

const charMap = {
'<': '\\u003C',
'>' : '\\u003E',
'/': '\\u002F',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
};

function escapeUnsafeChars(str) {
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, x => charMap[x])
}

class TagRefImpl<TTag extends string, T extends Tag<TTag> | TypedCustomTag<TTag, U>, U>
@@ -222,3 +241,3 @@
{
result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${JSON.stringify(tag.attributes.id.value)}))})` });
result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${escapeUnsafeChars(JSON.stringify(e[0]))}, ${escapeUnsafeChars(e[1].toString())})`).join(';' + prefix)}})(document.getElementById(${escapeUnsafeChars(JSON.stringify(tag.attributes.id.value))}))})` });
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

if (tag.event && tag.attributes.id)
{
result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${JSON.stringify(tag.attributes.id.value)}))})` });

Check warning

Code scanning / CodeQL

Improper code sanitization

Code construction depends on an [improperly sanitized value](1). Code construction depends on an [improperly sanitized value](2).

Copilot Autofix AI 3 months ago

To fix the problem, we need to ensure that any user-controlled input is properly sanitized before being included in the dynamically generated script tag. We can achieve this by escaping potentially dangerous characters in the input. We will create a function to escape unsafe characters and use it to sanitize tag.attributes.id.value before including it in the script tag.

  1. Create a function escapeUnsafeChars to escape potentially dangerous characters.
  2. Use this function to sanitize tag.attributes.id.value before including it in the script tag.
Suggested changeset 1
packages/pages/src/dom-walker.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/pages/src/dom-walker.ts b/packages/pages/src/dom-walker.ts
--- a/packages/pages/src/dom-walker.ts
+++ b/packages/pages/src/dom-walker.ts
@@ -90,2 +90,21 @@
 
+const charMap = {
+    '<': '\\u003C',
+    '>': '\\u003E',
+    '/': '\\u002F',
+    '\\': '\\\\',
+    '\b': '\\b',
+    '\f': '\\f',
+    '\n': '\\n',
+    '\r': '\\r',
+    '\t': '\\t',
+    '\0': '\\0',
+    '\u2028': '\\u2028',
+    '\u2029': '\\u2029'
+};
+
+function escapeUnsafeChars(str) {
+    return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, x => charMap[x]);
+}
+
 export function escapeXml(text: string)
@@ -222,3 +241,3 @@
             {
-                result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${JSON.stringify(tag.attributes.id.value)}))})` });
+                result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${escapeUnsafeChars(JSON.stringify(tag.attributes.id.value))}))})` });
             }
EOF
@@ -90,2 +90,21 @@

const charMap = {
'<': '\\u003C',
'>': '\\u003E',
'/': '\\u002F',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
};

function escapeUnsafeChars(str) {
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, x => charMap[x]);
}

export function escapeXml(text: string)
@@ -222,3 +241,3 @@
{
result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${JSON.stringify(tag.attributes.id.value)}))})` });
result += renderOuter({ type: 'script', content: `addEventListener('load', function(){(function(el){${Object.entries(tag.event).map(e => `el.addEventListener(${JSON.stringify(e[0])}, ${e[1]})`).join(';' + prefix)}})(document.getElementById(${escapeUnsafeChars(JSON.stringify(tag.attributes.id.value))}))})` });
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
{
if (keys.length == i + 1)
{
config[key] = newConfig;

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1).

Copilot Autofix AI about 1 month ago

To fix the prototype pollution vulnerability, we need to ensure that the key parameter does not contain any values that could modify the Object.prototype. We can achieve this by checking if the key contains any forbidden properties like __proto__, constructor, or prototype before using it to modify the config object.

Suggested changeset 1
packages/config/src/configuration.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/config/src/configuration.ts b/packages/config/src/configuration.ts
--- a/packages/config/src/configuration.ts
+++ b/packages/config/src/configuration.ts
@@ -271,2 +271,5 @@
         const keys = key.split('.');
+        if (keys.includes('__proto__') || keys.includes('constructor') || keys.includes('prototype')) {
+            throw new Error('Invalid key');
+        }
         keys.reduce(function (config, key, i)
EOF
@@ -271,2 +271,5 @@
const keys = key.split('.');
if (keys.includes('__proto__') || keys.includes('constructor') || keys.includes('prototype')) {
throw new Error('Invalid key');
}
keys.reduce(function (config, key, i)
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
// console.log(config);
}
else if (typeof (config[key]) == 'undefined')
config[key] = {};

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1).

Copilot Autofix AI about 1 month ago

To fix the prototype pollution vulnerability, we need to ensure that the key value cannot be used to modify Object.prototype. One way to achieve this is by checking if any part of the key is __proto__, constructor, or prototype and rejecting such inputs. This can be done by adding a validation step before using the key to modify the config object.

Suggested changeset 1
packages/config/src/configuration.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/config/src/configuration.ts b/packages/config/src/configuration.ts
--- a/packages/config/src/configuration.ts
+++ b/packages/config/src/configuration.ts
@@ -271,2 +271,5 @@
         const keys = key.split('.');
+        if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
+            throw new Error('Invalid key');
+        }
         keys.reduce(function (config, key, i)
EOF
@@ -271,2 +271,5 @@
const keys = key.split('.');
if (keys.some(k => k === '__proto__' || k === 'constructor' || k === 'prototype')) {
throw new Error('Invalid key');
}
keys.reduce(function (config, key, i)
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
return;
if (typeof config[key] !== 'undefined' && keys.length == i + 1)
{
delete config[key];

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1).

Copilot Autofix AI about 1 month ago

To fix the prototype pollution vulnerability, we need to ensure that the key parameter cannot be __proto__, constructor, or prototype. This can be done by adding a check at the beginning of the delete method to reject these values. Additionally, we should use a safer data structure like Map to store the configuration, but for minimal changes, we will implement the key validation.

Suggested changeset 1
packages/config/src/configuration.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/config/src/configuration.ts b/packages/config/src/configuration.ts
--- a/packages/config/src/configuration.ts
+++ b/packages/config/src/configuration.ts
@@ -299,2 +299,5 @@
     {
+        if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
+            throw new Error('Invalid key');
+        }
         const keys = key.split('.');
EOF
@@ -299,2 +299,5 @@
{
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
throw new Error('Invalid key');
}
const keys = key.split('.');
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const formatter = formatters.resolve<(new (...args: unknown[]) => Formatter<unknown>)>(`#${expression.formatter}`);
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
if (result.settings)
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call

Invocation of method with [user-controlled](1) name may dispatch to unexpected target and cause an exception.

Copilot Autofix AI 3 days ago

To fix the problem, we need to add a more robust validation for the formatter before it is used. Specifically, we should ensure that the formatter is a function and, if it is to be instantiated, that it is a valid constructor. We can achieve this by using a combination of typeof checks and instanceof checks.

  1. Add a check to ensure that formatter is a function.
  2. Add a check to ensure that formatter is a valid constructor if it is to be instantiated.
  3. Modify the code to handle cases where the formatter is not valid by returning an appropriate error message or taking other corrective actions.
Suggested changeset 1
packages/core/src/observables/object.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/core/src/observables/object.ts b/packages/core/src/observables/object.ts
--- a/packages/core/src/observables/object.ts
+++ b/packages/core/src/observables/object.ts
@@ -249,9 +249,32 @@
             const formatter = expression.formatter;
-            if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
-                if (result.settings)
-                    result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
-                else
-                    result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value) };
-            else
-                result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };
+            if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter) {
+                if (result.settings) {
+                    result.getter = (target, watcher) => {
+                        const value = source(target, watcher);
+                        if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter) {
+                            return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value);
+                        } else {
+                            throw new Error('Invalid formatter function');
+                        }
+                    };
+                } else {
+                    result.getter = (target, watcher) => {
+                        const value = source(target, watcher);
+                        if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter) {
+                            return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value);
+                        } else {
+                            throw new Error('Invalid formatter function');
+                        }
+                    };
+                }
+            } else {
+                result.getter = (target, watcher) => {
+                    const value = source(target, watcher);
+                    if (typeof formatter === 'function') {
+                        return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value);
+                    } else {
+                        throw new Error('Invalid formatter function');
+                    }
+                };
+            }
         }
EOF
@@ -249,9 +249,32 @@
const formatter = expression.formatter;
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
if (result.settings)
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value) };
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter) {
if (result.settings) {
result.getter = (target, watcher) => {
const value = source(target, watcher);
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter) {
return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value);
} else {
throw new Error('Invalid formatter function');
}
};
} else {
result.getter = (target, watcher) => {
const value = source(target, watcher);
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter) {
return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value);
} else {
throw new Error('Invalid formatter function');
}
};
}
} else {
result.getter = (target, watcher) => {
const value = source(target, watcher);
if (typeof formatter === 'function') {
return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value);
} else {
throw new Error('Invalid formatter function');
}
};
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
if (result.settings)
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value) };

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call

Invocation of method with [user-controlled](1) name may dispatch to unexpected target and cause an exception.

Copilot Autofix AI 3 days ago

To fix the problem, we need to ensure that the formatter is a valid function and is an own property of the expression object. We can achieve this by using Object.prototype.hasOwnProperty.call to check if formatter is an own property and typeof to check if it is a function. This will prevent any unexpected method calls and runtime exceptions.

Suggested changeset 1
packages/core/src/observables/object.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/core/src/observables/object.ts b/packages/core/src/observables/object.ts
--- a/packages/core/src/observables/object.ts
+++ b/packages/core/src/observables/object.ts
@@ -249,3 +249,3 @@
             const formatter = expression.formatter;
-            if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
+            if (Object.prototype.hasOwnProperty.call(expression, 'formatter') && typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
                 if (result.settings)
EOF
@@ -249,3 +249,3 @@
const formatter = expression.formatter;
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
if (Object.prototype.hasOwnProperty.call(expression, 'formatter') && typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
if (result.settings)
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value) };
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call

Invocation of method with [user-controlled](1) name may dispatch to unexpected target and cause an exception.

Copilot Autofix AI 3 days ago

To fix the problem, we need to ensure that the formatter variable is validated more thoroughly before it is used. Specifically, we should:

  1. Check if formatter is an own property of the formatters object to ensure it is a valid formatter function.
  2. Verify that formatter is indeed a function before invoking it.

This can be achieved by modifying the code in packages/core/src/observables/object.ts to include these additional checks.

Suggested changeset 1
packages/core/src/observables/object.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/core/src/observables/object.ts b/packages/core/src/observables/object.ts
--- a/packages/core/src/observables/object.ts
+++ b/packages/core/src/observables/object.ts
@@ -249,9 +249,9 @@
             const formatter = expression.formatter;
-            if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
+            if (formatters.hasOwnProperty(formatter) && typeof formatters[formatter] === 'function' && formatters[formatter].prototype instanceof WatcherFormatter)
                 if (result.settings)
-                    result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
+                    result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatters[formatter](result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
                 else
-                    result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value) };
+                    result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatters[formatter](watcher))).format(value instanceof ObservableObject ? value.target : value) };
             else
-                result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };
+                result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatters[formatter](result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };
         }
EOF
@@ -249,9 +249,9 @@
const formatter = expression.formatter;
if (typeof formatter === 'function' && formatter.prototype instanceof WatcherFormatter)
if (formatters.hasOwnProperty(formatter) && typeof formatters[formatter] === 'function' && formatters[formatter].prototype instanceof WatcherFormatter)
if (result.settings)
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatters[formatter](result.settings(target, watcher), watcher))).format(value instanceof ObservableObject ? value.target : value) };
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(watcher))).format(value instanceof ObservableObject ? value.target : value) };
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatters[formatter](watcher))).format(value instanceof ObservableObject ? value.target : value) };
else
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatter(result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };
result.getter = (target, watcher) => { const value = source(target, watcher); return (result.formatterInstance || (result.formatterInstance = new formatters[formatter](result.settings?.(target, watcher)))).format(value instanceof ObservableObject ? value.target : value) };
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

// let formatterInstance: ReversibleFormatter<unknown, unknown>;
if (previousSetter)
setter = (target: T, value: TValue) => previousSetter.setter(target, ((formatterGetter.formatterInstance || (formatterGetter.formatterInstance = new formatter(formatterGetter.settings?.(target, null)))) as ReversibleFormatter<unknown, unknown>).unformat(value));

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call

Invocation of method with [user-controlled](1) name may dispatch to unexpected target and cause an exception.

public parseString(expression: string, start: string, parseFormatter: boolean)
{
const evaluatedRegex = new RegExp("^" + start + "((?:[^\\" + start + "]|\\.)*)" + start).exec(expression);

Check failure

Code scanning / CodeQL

Regular expression injection

This regular expression is constructed from a [user-provided value](1).

Copilot Autofix AI 3 days ago

To fix the problem, we need to sanitize the start parameter before using it to construct the regular expression. The best way to do this is by using a sanitization function such as _.escapeRegExp from the lodash library. This function escapes special characters in the input string, making it safe to use in a regular expression.

  1. Install the lodash package if it is not already installed.
  2. Import the _.escapeRegExp function from lodash.
  3. Use _.escapeRegExp to sanitize the start parameter before constructing the regular expression.
Suggested changeset 2
packages/core/src/parser/parser.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/core/src/parser/parser.ts b/packages/core/src/parser/parser.ts
--- a/packages/core/src/parser/parser.ts
+++ b/packages/core/src/parser/parser.ts
@@ -10,3 +10,3 @@
 import { formatters } from '../formatters/index.js';
-
+import _ from 'lodash';
 
@@ -551,3 +551,4 @@
     {
-        const evaluatedRegex = new RegExp("^" + start + "((?:[^\\" + start + "]|\\.)*)" + start).exec(expression);
+        const safeStart = _.escapeRegExp(start);
+        const evaluatedRegex = new RegExp("^" + safeStart + "((?:[^\\" + safeStart + "]|\\.)*)" + safeStart).exec(expression);
         // console.log(arguments);
EOF
@@ -10,3 +10,3 @@
import { formatters } from '../formatters/index.js';

import _ from 'lodash';

@@ -551,3 +551,4 @@
{
const evaluatedRegex = new RegExp("^" + start + "((?:[^\\" + start + "]|\\.)*)" + start).exec(expression);
const safeStart = _.escapeRegExp(start);
const evaluatedRegex = new RegExp("^" + safeStart + "((?:[^\\" + safeStart + "]|\\.)*)" + safeStart).exec(expression);
// console.log(arguments);
packages/core/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/core/package.json b/packages/core/package.json
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -63,3 +63,4 @@
         "debug": "^4.3.7",
-        "reflect-metadata": "^0.2.2"
+        "reflect-metadata": "^0.2.2",
+        "lodash": "^4.17.21"
     },
EOF
@@ -63,3 +63,4 @@
"debug": "^4.3.7",
"reflect-metadata": "^0.2.2"
"reflect-metadata": "^0.2.2",
"lodash": "^4.17.21"
},
This fix introduces these dependencies
Package Version Security advisories
lodash (npm) 4.17.21 None
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant