Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
eb796fb4
Commit
eb796fb4
authored
8 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh] Remove `eval` code
parent
a28c08b1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.eslintrc
+1
-1
1 addition, 1 deletion
.eslintrc
app/cli.js
+4
-4
4 additions, 4 deletions
app/cli.js
app/lib/streams/sanitize.js
+29
-8
29 additions, 8 deletions
app/lib/streams/sanitize.js
with
34 additions
and
13 deletions
.eslintrc
+
1
−
1
View file @
eb796fb4
...
...
@@ -22,6 +22,7 @@
"no-trailing-spaces": 0,
"no-unused-expressions": 0,
"comma-spacing": 0,
"no-eval": 0,
"quotes": [0, "double"],
"linebreak-style": [1,"unix"],
...
...
@@ -30,7 +31,6 @@
"no-process-exit": [1],
"indent": [1,2],
"no-eval": [1],
"comma-dangle": [1],
"eol-last": [1],
"no-shadow": [1],
...
...
This diff is collapsed.
Click to expand it.
app/cli.js
+
4
−
4
View file @
eb796fb4
...
...
@@ -304,7 +304,7 @@ program
program
.
command
(
'
gen-next [host] [port] [difficulty]
'
)
.
description
(
'
Tries to generate the next block of the blockchain
'
)
.
action
(
subCommand
(
service
(
generateAndSend
(
"
generateNext
"
))));
.
action
(
subCommand
(
service
(
generateAndSend
(
(
server
)
=>
server
.
BlockchainService
.
generateNext
))));
program
.
command
(
'
gen-root [host] [port] [difficulty]
'
)
...
...
@@ -319,15 +319,15 @@ program
if
(
!
difficulty
)
{
throw
'
Difficulty is required.
'
;
}
return
generateAndSend
(
"
generateManualRoot
"
)(
host
,
port
,
difficulty
,
server
,
conf
);
return
generateAndSend
(
(
server
)
=>
server
.
BlockchainService
.
generateManualRoot
)(
host
,
port
,
difficulty
,
server
,
conf
);
})));
function
generateAndSend
(
generationMethod
)
{
function
generateAndSend
(
ge
tGe
nerationMethod
)
{
return
function
(
host
,
port
,
difficulty
,
server
,
conf
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
async
.
waterfall
([
function
(
next
)
{
var
method
=
eval
(
'
server.BlockchainService.
'
+
g
enerationMethod
);
const
method
=
getG
enerationMethod
(
server
);
co
(
function
*
(){
try
{
const
block
=
yield
method
();
...
...
This diff is collapsed.
Click to expand it.
app/lib/streams/sanitize.js
+
29
−
8
View file @
eb796fb4
...
...
@@ -63,25 +63,46 @@ module.exports = function sanitize (json, contract) {
// Check coherence & alter member if needed
if
(
!
_
(
json
[
prop
]).
isNull
()
&&
t
.
toLowerCase
()
!=
tjson
.
toLowerCase
())
{
try
{
if
(
t
==
"
String
"
||
t
==
"
Number
"
)
{
if
(
t
==
"
String
"
)
{
let
s
=
json
[
prop
]
==
undefined
?
''
:
json
[
prop
];
eval
(
'
json[prop] = new
'
+
t
+
'
(
'
+
s
+
'
).valueOf()
'
);
json
[
prop
]
=
String
(
s
).
valueOf
();
}
else
if
(
t
==
"
Number
"
)
{
let
s
=
json
[
prop
]
==
undefined
?
''
:
json
[
prop
];
json
[
prop
]
=
Number
(
s
).
valueOf
();
}
else
if
(
t
==
"
Array
"
)
{
json
[
prop
]
=
[];
}
else
if
(
t
==
"
Object
"
)
{
json
[
prop
]
=
{};
}
else
{
eval
(
'
json[prop] =
new
'
+
t
+
'
()
'
);
json
[
prop
]
=
Boolean
(
);
}
}
catch
(
ex
)
{
eval
(
'
json[prop] = new
'
+
t
+
'
()
'
);
if
(
t
==
"
String
"
)
{
json
[
prop
]
=
String
();
}
else
if
(
t
==
"
Number
"
)
{
json
[
prop
]
=
Number
();
}
else
if
(
t
==
"
Array
"
)
{
json
[
prop
]
=
[];
}
else
if
(
t
==
"
Object
"
)
{
json
[
prop
]
=
{};
}
else
{
json
[
prop
]
=
Boolean
();
}
}
}
// Arrays
if
(
t
==
'
Array
'
)
{
let
subt
=
propType
[
0
];
for
(
let
j
=
0
,
len2
=
json
[
prop
].
length
;
j
<
len2
;
j
++
)
{
if
(
subt
==
"
String
"
||
subt
==
"
Number
"
)
{
eval
(
'
item = new
'
+
t
+
'
(
'
+
(
json
[
prop
]
+
''
)
+
'
).valueOf()
'
);
}
else
{
if
(
!
(
subt
==
"
String
"
||
subt
==
"
Number
"
))
{
json
[
prop
][
j
]
=
sanitize
(
json
[
prop
][
j
],
subt
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment