I've been researching What for a project, and here's a summary of what I found useful.
Want to learn advanced techniques? Check out our premium courses.
正文
What is JavaScript Security? What is JavaScript Security?
JavaScript is a widely-used client-side programming language, but it can run on the server as well. Like any programming language, applications written in JavaScript can contain vulnerabilities that attackers can exploit for various purposes.
JavaScript security includes the processes and tools used to secure JavaScript. This includes identifying these vulnerabilities in applications and taking steps to eliminate them during the development process or prevent them from being exploited in production.
As a primarily front-end language, JavaScript applications are especially vulnerable to attack because the application’s code is accessible to the user. This makes it much easier for an attacker to identify and exploit vulnerabilities in a front-end application. Also, an attacker has the ability to modify the code in their browser or send requests directly to the server-side applications, bypassing front-end protections.
JavaScript’s unique exposure makes it vitally important to find and fix vulnerabilities before they can be exploited by an attacker. JavaScript security helps organizations to do so by identifying known vulnerabilities in the organization’s JavaScript code.
JavaScript applications are not compiled, meaning that the source code is visible throughout its lifecycle. While this has security downsides, it also means that these applications can be easily analyzed via static application security testing (SAST).
SAST tools will analyze the source code of an application for known vulnerabilities or other issues. For example, a JavaScript security tool might look for the use of the eval() command in JavaScript, which provides unsafe access to the terminal. It may also check the dependencies used by the application for ones with known vulnerabilities or that are known to be malicious.
can be performed manually, providing a developer or security team member with a complete report on an application’s vulnerabilities. Alternatively, JavaScript security scanning can be built into automated DevOps workflows so that vulnerabilities are found and fixed before code can be committed to a repo.
JavaScript applications can contain a range of potential vulnerabilities. Some of the most common include the following:
JavaScript applications may contain coding errors that create vulnerabilities in the application. This is especially dangerous with client-side JavaScript because attackers can easily read the code and search for issues.
JavaScript applications commonly use third-party libraries available via npm or similar sources. These libraries may include vulnerabilities or malicious code that makes the application vulnerable.
A failure to validate user input before processing it can create injection vulnerabilities. This can lead to various types of injection attacks depending on the format of the data and its use. Cross-Site Scripting (XSS):
XSS vulnerabilities allow an attacker to inject malicious JavaScript code into a webpage. This code can be used to steal sensitive data or take other malicious actions. Cross-Site Request Forgery:
In a CSRF attack, the attacker tricks a user’s browser into performing requests to a website that they have already authenticated to. This could allow an attacker to change the user’s password on the site, perform a bank transaction, make social media posts, or take other undesirable actions.
JavaScript code has the ability to access sensitive data in a web request such as the values stored in HTTP cookies. This can be used to steal session ID tokens that enable the attacker to hijack an authenticated user’s session with the webpage.
More Details
There are a few more points worth noting. First, browser compatibility varies across different browsers. Second, performance optimization is crucial when handling large amounts of data. Finally, key management is also an important consideration.
Feel free to ask questions in the comments - I'll reply as soon as possible.
Reference: What is JavaScript Security?