How can javascript interpreters such as phpv8js only check the syntax of js Code and not execute it?

Source: Internet
Author: User
Recently, I used PHP as a small software program in my company. I have several requirements for verifying the syntax of the JS Code submitted by users. I installed the v8js extension and wrapped the submitted code in the function & quot; varxfunction () {user JS Code} & quot ;, use this method to verify the customer code without executing it... recently, I used PHP as a small software program in my company. I have several requirements for verifying the syntax of the JS Code submitted by users. I installed the v8js extension and wrapped the submitted code in the function "var x = function () {user JS Code }", this method is used to verify the customer code without executing it.

The experiment works well, but the problem is that the above method may be used by smart users, resulting in the risk of injection. for example, the customer enters the code "}; some dangerous code", which may cause great trouble.

Is there any way to verify the syntax of the JS Code without executing the JS Code?

V8js extension documentation: http://cn2.php.net/manual/zh/class.v8js.php

Reply content:

Recently, I used PHP as a small software program in my company. I have several requirements for verifying the syntax of the JS Code submitted by users. I installed the v8js extension and wrapped the submitted code in the function "var x = function () {user JS Code }", this method is used to verify the customer code without executing it.

The experiment works well, but the problem is that the above method may be used by smart users, resulting in the risk of injection. for example, the customer enters the code "}; some dangerous code", which may cause great trouble.

Is there any way to verify the syntax of the JS Code without executing the JS Code?

V8js extension documentation: http://cn2.php.net/manual/zh/class.v8js.php

Try javascriptlint or jslint.

Tracking code found that in PHP's V8 extension, JavaScript verification is performed inside the code before execution. Therefore, you only need to modify the code and let it return after verification, you can check the syntax without executing the code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.