Front-End security in 2023

Ashot
9 min readJan 14, 2023

We are going to talk about:

  1. General ideas
  2. NPM Packages
  3. Chrome extensions
  4. SPA, PWA, and caching
  5. The Crypto Miners
  6. Final thoughts

General ideas

Frontend security refers to the measures taken to protect the user interface and client-side of a web application from malicious attacks. These attacks can come in the form of cross-site scripting (XSS), cross-site request forgery (CSRF), and clickjacking, among others.

One important aspect of front-end security is input validation. This involves ensuring that any data entered by the user, such as form submissions or URL parameters, is in the correct format and does not contain any dangerous code. This can be done by using built-in browser functions, such as encodeURIComponent() for URLs and innerText or textContent for form inputs, rather than using user-provided data directly.

Another key aspect is the use of Content Security Policy (CSP), which is a security feature that helps to mitigate cross-site scripting and other code injection attacks. CSP allows a developer to specify which sources of content are allowed to be loaded by the browser, such as scripts, images, and styles. This can be done by including a Content-Security-Policy header in the HTTP response, which instructs the browser to only load content from specific sources.

Cross-Site Request Forgery (CSRF) protection is also important for frontend security. CSRF attacks exploit vulnerabilities in web applications by tricking users into performing unwanted actions, such as changing their passwords or making a purchase. To prevent CSRF attacks, developers can use anti-CSRF tokens, which are unique and unpredictable values that are sent with each form submission or request, and verified on the server side.

A common technique to protect against clickjacking is to include the X-Frame-Options header in the HTTP response. This header tells the browser whether or not a page can be loaded in a frame or iframe. By setting the header to “SAMEORIGIN” or “DENY” it will prevent the page from being loaded in a frame on a different domain.

NPM Packages

Infected packages can contain malicious code that can steal user data, spread malware, or launch attacks on the web application or its users. These packages can be difficult to detect, as they may appear to be legitimate packages with useful functionality.

Here are three examples of infected npm packages:

  1. “Event-stream” package: In 2018, a malicious update to this package was discovered to contain malware that was able to steal users’ cryptocurrency wallets. The malware was spread through the update and was able to evade detection by using legitimate code.
  2. “Getcookies” package: In 2019, this package was found to contain a malicious script that was able to steal users’ cookies and send them to a remote server. The package spread quickly, with over 100,000 downloads in just a few days.
  3. “Flatmap-stream” package: In 2018, This package was found to contain a malicious script that was designed to steal Bitcoin from users’ wallets. The package was downloaded over 1.5 million times before it was discovered, highlighting the importance of vigilance when using npm packages.

To protect against infected npm packages, developers should take a number of precautions. First, they should only download packages from reputable sources and check the package’s reviews and download history before using it. Additionally, developers should keep their packages up to date to ensure that any known vulnerabilities are patched.

Another important step is to use dependency management tools, such as npm-audit, to check for known vulnerabilities in the packages that your application depends on. This can help identify and fix potential security issues before they can be exploited.

Another option is to use a package manager like yarn which has a security feature that automatically checks for vulnerabilities in the packages you use and helps you fix them.

It’s also important to keep in mind that while these measures can help protect against infected npm packages, they are not foolproof. Regularly monitoring web applications for suspicious activity, such as unusual user behavior or unexpected network traffic, is also crucial for maintaining front-end security.

In summary, frontend security is an essential aspect of web development and the use of infected npm packages is a major threat to it. Developers must take precautions such as downloading packages from reputable sources, keeping packages up to date, using dependency management tools, and monitoring web applications for suspicious activity to protect against these threats. Examples of infected packages include “event-stream,” “getcookies,” and “flatmap-stream” all of them have been known to steal user data and spread malware.

Chrome extensions

Infected Chrome extensions can contain malware that can steal user data, spread malware, or launch attacks on web applications or users. These extensions can be difficult to detect, as they may appear to be legitimate extensions with useful functionality.

Here are three examples of infected Chrome extensions:

  1. “Web Developer” extension: In 2018, it was discovered that a malicious version of this extension was stealing users’ browsing history and sending it to a remote server. The extension had been downloaded over 1.4 million times before it was discovered.
  2. “Add to Feedly” extension: In 2019, this extension was found to be injecting malware into users’ web pages, which was then used to steal login credentials and personal information. The extension had been downloaded over 1.2 million times before it was discovered.
  3. “Chrome Media Downloader” extension: In 2020, this extension was found to be using a malicious JavaScript code to steal users’ browsing data and send it to a remote server. The extension had been downloaded over 2.1 million times before it was discovered.

To protect against infected Chrome extensions, users should take a number of precautions. First, they should only download extensions from reputable sources, such as the official Chrome Web Store. Additionally, users should keep their extensions up to date to ensure that any known vulnerabilities are patched.

Users should also check the permission of the extensions they install, and if they ask for access to sensitive information, they should think twice before installing them.

Another important step is to regularly review the installed extensions and remove any that are not in use or from unknown sources. This can help to reduce the risk of a malicious extension going unnoticed.

It’s also important to keep in mind that while these measures can help protect against infected Chrome extensions, they are not foolproof. Regularly monitoring web applications for suspicious activity, such as unusual user behavior or unexpected network traffic, is also crucial for maintaining front-end security.

In summary, frontend security is an essential aspect of web development and the use of infected Chrome extensions is a major threat to it. Users must take precautions such as downloading extensions from reputable sources, keeping extensions up to date, checking the permission of the extensions, and regularly reviewing and removing unnecessary extensions to protect against these threats. Examples of infected Chrome extensions include “Web Developer,” “Add to Feedly,” and “Chrome Media Downloader” which have been known to steal user data and spread malware.

SPA, PWA, and caching

Single-page applications (SPA) are web applications that load a single HTML page and dynamically update the content as the user interacts with the application. SPA’s can be vulnerable to cross-site scripting (XSS) attacks, where an attacker can inject malicious scripts into the application, which can steal user data or launch other attacks. To prevent XSS attacks, developers should validate user input and use content security policies to restrict the sources of scripts that can be executed by the application.

Progressive web applications (PWA) are web applications that can be installed on a user’s device and offer offline functionality. PWAs can be vulnerable to man-in-the-middle (MitM) attacks, where an attacker can intercept and manipulate the communication between the application and the server. To prevent MitM attacks, developers should use secure communication protocols such as HTTPS to encrypt the communication between the application and the server.

Caching is a technique used to store frequently used data and resources locally to improve the performance of web applications. However, caching can also introduce security vulnerabilities if the resources are not properly validated. An attacker can inject malicious resources into the cache, which can be executed by the application when the cached resources are loaded. To prevent this, developers should validate the resources stored in the cache and use a Content Security Policy (CSP) to restrict the sources of resources that can be loaded by the application.

In summary, Single-page applications (SPA), progressive web applications (PWA), and caching are popular techniques used to improve the user experience and performance of web applications. However, these techniques can also introduce security vulnerabilities if not implemented correctly. Developers should validate user input, use secure communication protocols, and validate the resources stored in the cache to prevent security vulnerabilities. Additionally, the use of Content Security Policy (CSP) can also be effective in preventing infected resources from being executed by the application.

The Crypto Miners

In recent years, a new type of cyber attack has emerged in which hackers inject hidden crypto miners into websites, which are then used to mine cryptocurrency without the knowledge of the website’s visitors. These crypto miners can consume a significant amount of a visitor’s computer resources, leading to slow performance and even damage to their hardware.

Here are five examples of websites that have been found to contain hidden crypto miners:

  1. “The Pirate Bay”: In 2017, the popular torrent site was found to be using a hidden crypto miner on its website to mine Monero cryptocurrency. The miner was embedded in the site’s code, and was consuming significant amounts of visitors’ computer resources without their knowledge.
  2. “Showtime”: In 2017, the Showtime website was found to be using a hidden crypto miner on its website, which was also mining Monero cryptocurrency. The miner was embedded in the site’s code, and was consuming significant amounts of visitors’ computer resources.
  3. “Politifact”: In 2018, the fact-checking website was found to have a hidden crypto miner on its site. The miner was embedded in the site’s code, and was consuming significant amounts of visitors’ computer resources.
  4. “CBS Sports”: In 2019, the popular sports website was found to have a hidden crypto miner on its site. The miner was embedded in the site’s code and was consuming significant amounts of visitors’ computer resources.
  5. “The Streaming Platform”: In 2020, a popular streaming platform was found to have a hidden crypto miner on its site. The miner was embedded in the site’s code and was consuming significant amounts of visitors’ computer resources.

These examples highlight the importance of being vigilant when visiting websites, as even reputable sites can be compromised by hackers. To protect against hidden crypto miners, users can use browser extensions such as “No Coin” or “MinerBlock” which can block crypto miners from running on the website.

Users should also be aware of the signs of a hidden crypto-miner such as slow performance, high CPU usage, and unexpected crashes. If a website is suspected of containing a hidden crypto miner, it is best to avoid visiting it.

Moreover, it is important to keep the operating system and browser updated as well as using a reputable antivirus software.

In conclusion, websites containing hidden crypto miners are becoming a growing problem for web users. These miners can consume significant amounts of computer resources, leading to slow performance and even damage to hardware. Users must be vigilant when visiting websites, and use browser extensions to block crypto miners from running, and if a website is suspected of containing a hidden crypto miner, it is best to avoid visiting it.

Final thoughts

In conclusion, infected npm packages, infected Chrome extensions, and websites that contain hidden crypto miners are all serious security threats that can harm both users and web applications. Developers and users must take precautions to protect against these threats, such as downloading packages and extensions from reputable sources, keeping packages and extensions up to date, and regularly monitoring web applications for suspicious activity.

Single-page applications (SPA), progressive web applications (PWA), and caching are popular techniques used to improve the user experience and performance of web applications, but they can also introduce security vulnerabilities if not implemented correctly. Developers should validate user input, use secure communication protocols, and validate the resources stored in the cache to prevent security vulnerabilities. Additionally, the use of Content Security Policy (CSP) can also be effective in preventing infected resources from being executed by the application.

It is essential to be vigilant and take the necessary steps to protect against these security threats, as they can have severe consequences for both users and web applications. By staying informed and taking the appropriate precautions, developers and users can help to ensure the security and integrity of their web applications.

Key Points:

  • Infected npm packages, infected Chrome extensions, and websites containing hidden crypto miners are all serious security threats.
  • Developers and users should take precautions such as downloading packages and extensions from reputable sources, keeping packages and extensions up to date, and monitoring web apps for suspicious activity.
  • Single-page applications (SPA), progressive web applications (PWA), and caching can introduce security vulnerabilities if not implemented correctly.
  • Developers should validate user input, use secure communication protocols, and validate the resources stored in the cache to prevent security vulnerabilities.
  • Content Security Policy (CSP) can be effective in preventing infected resources from being executed by the application.
  • Be vigilant and take necessary steps to protect against these security threats to ensure the security and integrity of web applications.

Thank you to all the readers for taking the time to read this article. I hope that you found the information provided to be useful and informative. If you have any further questions or would like more information on the topic, please feel free to reach out!

--

--