0

can anyone help me to enable the use of Eval() and Function() in couchdb design document.

I am trying to use eval() and Function methods in _list function but it always shows the below error when I call the list

{ "code": 500, "error": "render_error", "reason": "function raised error: (new Error(\"call to eval() blocked by CSP\", \"lists.testing\", 1)) \nstacktrace: ([object Object],[object Object])@lists.testing:1\nrunList(function (head, req) {var

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
  • This sounds like a possible XY Problem. Why are you trying to eval code in a view function? What is it you're ultimately trying to accomplish? – Jonathan Hall May 09 '18 at 08:48
  • If one of the answers below answered your question, the way this site works, you'd "accept" the answer, more here: [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers). But only if your question really has been answered. If not, consider adding more details to the question. – Juanjo Rodriguez May 14 '18 at 08:25

1 Answers1

1

The eval function has been disabled by default in couchjs which is the process that evaluates the JavaScript functions defined in the design documents. You can see this change in this commit.

It seems that eval can produce some risks on the system as it can be used as a mechanism to run not controlled code in the server.

If you assume the risk, I suppose that you can reenable it by overriding the [query_servers] javascript config property in your local.ini config file. You need to add the --eval argument to the couchjs command.

[query_servers]
javascript = ./bin/couchjs --eval ./share/server/main.js
Juanjo Rodriguez
  • 2,103
  • 8
  • 19