This document outlines the security measures implemented in this project to ensure the safety and integrity of user data. We take security seriously and have taken steps to mitigate common web vulnerabilities.
-
Vulnerability: XSS attacks occur when malicious scripts are injected into a website. In this application, user-provided data was rendered directly to the DOM without proper sanitization, creating a risk of stored XSS.
-
Mitigation: We have implemented a two-pronged approach to prevent XSS:
- Input Sanitization: All user data is sanitized on the frontend using the
dompurifylibrary before it is stored inlocalStorageor rendered in the application. This is done insrc/utils/localStorage.tsandsrc/components/ApplicationTable.tsx. - Backend Sanitization: As a second layer of defense, all data sent to the backend is sanitized using
htmlspecialcharsin the PHP API. This ensures that even if malicious data is sent to the server, it is rendered harmless.
- Input Sanitization: All user data is sanitized on the frontend using the
-
Why this is a good practice: By sanitizing data at multiple layers (both on the client and server), we create a robust defense against XSS.
dompurifyis a well-regarded library that is highly effective at preventing XSS, andhtmlspecialcharsis a standard PHP function for escaping HTML.
-
Vulnerability: Injection attacks, such as SQL injection, occur when an attacker can send malicious data to an application that is then executed by the backend. While this application does not use a SQL database, it does interact with the Google Sheets API, and unsanitized data could still be sent to that service.
-
Mitigation: All user-provided data is sanitized on the backend using
htmlspecialcharsbefore it is processed or sent to the Google Sheets API. This is done inapi/google-sheets.php. We also validate the format of thespreadsheetIdto ensure it is a valid Google Sheets ID. -
Why this is a good practice: Sanitizing all data on the backend is a critical security measure that prevents a wide range of injection attacks. It ensures that the data is safe before it is used by the application or any external services.
-
Vulnerability: The PHP backend had a permissive CORS policy (
Access-Control-Allow-Origin: *), which would have allowed any website to make requests to the API. This could have enabled Cross-Site Request Forgery (CSRF) attacks and other malicious activities. -
Mitigation: We have implemented a strict CORS policy on the backend that only allows requests from the application's frontend. This is configured in all the PHP files in the
api/directory. -
Why this is a good practice: A strict CORS policy is essential for preventing unauthorized cross-origin requests. By only allowing requests from trusted origins, we can ensure that the API is only used by the intended frontend application.
If you discover a security vulnerability, please open an issue on GitHub. We will address it as quickly as possible.