-
Notifications
You must be signed in to change notification settings - Fork 258
Security Patch. #288
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
Open
sei-vsarvepalli
wants to merge
11
commits into
silentmatt:master
Choose a base branch
from
sei-vsarvepalli:secure-patch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−32
Open
Security Patch. #288
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
432900f
Remove user-defined function ability and member access
sei-renae 146ff83
restrict functions to ./functions.js
sei-renae 955f390
Updated 2.0.3 for secure expr-eval
sei-vsarvepalli 084b27c
Update the parser tests with parser.functions
sei-vsarvepalli 0cf073c
Updates to security.js
sei-vsarvepalli ae20d0a
Updated expr-eval package
sei-vsarvepalli 6a2bd62
npm updates were run
sei-vsarvepalli 1af7983
Updates devDependencies
sei-vsarvepalli bb9394e
Updates to README.md
sei-vsarvepalli bf11231
Added notes to test/parser.js
sei-vsarvepalli 46b2b83
Bumped version big jump and small updates from Gemini feedback
sei-vsarvepalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| import rollupConfig from './rollup.config'; | ||
| // rollup-esm.config.js (Converted to CommonJS) | ||
|
|
||
| rollupConfig.plugins = []; | ||
| rollupConfig.output.file = 'dist/index.mjs'; | ||
| rollupConfig.output.format = 'esm'; | ||
| // 1. Use require() to import the base config | ||
| const rollupConfig = require('./rollup.config.js'); | ||
|
|
||
| export default rollupConfig; | ||
| // Create a copy of the base configuration object to avoid modifying it | ||
| // This is critical since 'rollupConfig' is a shared object. | ||
| const esmConfig = { ...rollupConfig }; | ||
|
|
||
| // 2. Apply ESM-specific changes to the copied object | ||
| esmConfig.plugins = []; // No minification for the base ESM file | ||
| esmConfig.output = { | ||
| ...rollupConfig.output, | ||
| file: 'dist/index.mjs', | ||
| format: 'esm' | ||
| }; | ||
|
|
||
| // 3. Use module.exports to export the configuration | ||
| module.exports = esmConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,21 @@ | ||
| import rollupConfig from './rollup.config'; | ||
| import { uglify } from 'rollup-plugin-uglify'; | ||
| // rollup-min.config.js (Correct CommonJS Syntax) | ||
|
|
||
| rollupConfig.plugins = [ uglify() ]; | ||
| rollupConfig.output.file = 'dist/bundle.min.js'; | ||
| // 1. Use require() to import the base config and the terser plugin | ||
| const rollupConfig = require('./rollup.config.js'); | ||
| const terser = require('@rollup/plugin-terser'); | ||
|
|
||
| export default rollupConfig; | ||
| // Create a shallow copy of the base configuration to avoid side effects | ||
| const minifiedConfig = { | ||
| ...rollupConfig, | ||
| // Ensure the output property is also copied, if it exists | ||
| output: { ...rollupConfig.output } | ||
| }; | ||
|
|
||
| // 2. Set the plugins to ONLY include the terser plugin | ||
| minifiedConfig.plugins = [ terser() ]; | ||
|
|
||
| // 3. Update the file name | ||
| minifiedConfig.output.file = 'dist/bundle.min.js'; | ||
|
|
||
| // 4. Use module.exports to export the configuration | ||
| module.exports = minifiedConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 'use strict'; | ||
| var assert = require('assert'); | ||
| var Parser = require('../dist/bundle').Parser; | ||
| var fs = require('fs'); | ||
| var child_process = require('child_process'); | ||
|
|
||
| /* A context of potential dangerous stuff */ | ||
| var context = { | ||
| write: (path, data) => fs.writeFileSync(path, data), | ||
| cmd: (cmd) => console.log('Executing:', cmd), | ||
| exec: child_process.execSync | ||
| }; | ||
|
|
||
| it('should fail on direct function call to an unallowed function', function () { | ||
| var parser = new Parser(); | ||
| assert.throws(() => { | ||
| parser.evaluate('write("pwned.txt","Hello!")', context); | ||
| }, Error); | ||
| }); | ||
|
|
||
| it('should allow IFUNDEF but keep function calls safe', function () { | ||
| var parserWithFndef = new Parser({ | ||
| operators: { fndef: true } | ||
| }); | ||
| var safeExpr = '(f(x) = x * x)(5)'; | ||
| assert.equal(parserWithFndef.evaluate(safeExpr), 25, | ||
| 'Should correctly evaluate an expression with an allowed IFUNDEF.'); | ||
| var dangerousExpr = '((h(x) = write("pwned.txt", x)) + h(5))'; | ||
| assert.throws(() => { | ||
| parserWithFndef.evaluate(dangerousExpr, context); | ||
| }, Error); | ||
| }); | ||
|
|
||
| it('should fail when a variable is assigned a dangerous function', function () { | ||
| var parser = new Parser(); | ||
|
|
||
| var dangerousContext = { ...context, evil: context.cmd }; | ||
|
|
||
| assert.throws(() => { | ||
| parser.evaluate('evil("ls -lh /")', dangerousContext); | ||
| }, Error); | ||
| }); | ||
|
|
||
| it('PoC provided by researcher VU#263614 deny child exec process', function() { | ||
| var parser = new Parser(); | ||
| assert.throws(() => { | ||
| parser.evaluate('exec("whoami")', context); | ||
| }, Error); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this return
falseiffis not a function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check here is redundant anyways because we already check if the var is a function at the place where this is called. I'm guessing if it's not a function, then the expression is allowed because only functions are potentially malicious.