Skip to content

Commit aebe8f7

Browse files
committed
Fixed: security issue due to the usage of eval().
This is to avoid an arbitrary code execution. Now operations are resolved using [``math-expression-evaluator``](https://github.com/redhivesoftware/math- expression-evaluator)
1 parent da7bce7 commit aebe8f7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
- Fixed: security issue due to the usage of ``eval()``.
2+
This is to avoid an arbitrary code execution.
3+
Now operations are resolved using
4+
[``math-expression-evaluator``](https://github.com/redhivesoftware/math-expression-evaluator)
5+
16
# 1.2.4 - 2016-06-09
27

38
- Fixed: zero values are not unitless anymore.

index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
var balanced = require("balanced-match")
55
var reduceFunctionCall = require("reduce-function-call")
6+
var mexp = require("math-expression-evaluator")
67

78
/**
89
* Constantes
@@ -31,6 +32,10 @@ function reduceCSSCalc(value, decimalPrecision) {
3132
stack = 0
3233
decimalPrecision = Math.pow(10, decimalPrecision === undefined ? 5 : decimalPrecision)
3334

35+
// CSS allow to omit 0 for 0.* values,
36+
// but math-expression-evaluator does not
37+
value = value.replace(/\s(\.[0-9])/g, " 0$1")
38+
3439
/**
3540
* Evaluates an expression
3641
*
@@ -72,7 +77,7 @@ function reduceCSSCalc(value, decimalPrecision) {
7277
var result
7378

7479
try {
75-
result = eval(toEvaluate)
80+
result = mexp.eval(toEvaluate)
7681
}
7782
catch (e) {
7883
return functionIdentifier + "(" + expression + ")"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"name": "reduce-css-calc",
43
"version": "1.2.4",
@@ -16,6 +15,7 @@
1615
],
1716
"dependencies": {
1817
"balanced-match": "^0.1.0",
18+
"math-expression-evaluator": "^1.2.9",
1919
"reduce-function-call": "^1.0.1"
2020
},
2121
"devDependencies": {

0 commit comments

Comments
 (0)