{
  "id": 20928533,
  "title": "5 Security Mistakes I See in Flask + React Apps (and How to Fix Them)",
  "url": "https://urgent.news/2026/11/20/5-security-mistakes-i-see-in-flask-react-apps-and-how-to-fix-them",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-20T17:51:16.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/raqeeba_yasin/5-security-mistakes-i-see-in-flask-react-apps-and-how-to-fix-them-5ckj"
  },
  "original_language": "en",
  "account": "Flask and React are a popular combination for building web applications, offering speed, flexibility, and ease of deployment. However, the rapid development process can lead to overlooking security measures, which can have serious consequences if exploited. As a secure software engineer, I have observed five common mistakes that frequently appear in Flask+React applications. These issues are not complex and can be easily addressed with a few lines of code.\n\n1. Ignoring user input validation: The error occurs when developers directly read values from the `request.get_json()` method and treat them as safe and properly formatted. This approach can result in `KeyError` exceptions if fields are missing or in cases where unexpected data types or oversized strings are passed to other parts of the application. To prevent this, it is crucial to validate every request body against a defined schema before processing it. Pydantic is a recommended library for schema validation (install it using `pip install pydantic email-validator`).\n\n2. Storing JSON Web Tokens (JWTs) in localStorage: Saving the access token in `localStorage` exposes it to potential attacks, as any JavaScript running on the page can read this data. An XSS vulnerability, which can be introduced by an unsanitized dependency or a maliciously crafted piece of HTML, could allow an attacker to steal the session. To mitigate this risk, store the JWT in an `HttpOnly`, `Secure`, `SameSite` cookie. This ensures that JavaScript cannot access the token. With the Flask extension `flask-jwt-extended`, you can configure the application to use cookies for token storage:\n\n```python\n# ✅ After (Flask)\nfrom flask import jsonify\nfrom flask_jwt_extended import (JWTManager, create_access_token, set_access_cookies)\n\napp.config['JWT_TOKEN_LOCATION'] = ['cookies']\napp.config['JWT_COOKIE_SECURE'] = True # HTTPS only\napp.config['JWT_COOKIE_SAMESITE'] = 'Lax'\napp.config['JWT_COOKIE_CSRF_PROTECT'] = True # keep this on with cookies\n\njwt = JWTManager(app)\n\n@app.route('/login', methods=['POST'])\ndef login():\n# ...verify credentials...\ntoken = create_access_token(identity=str(user.id))\nresp = jsonify({'message': 'logged in'})\nset_access_cookies(resp, token)\nreturn resp\n```\n\nOn the React frontend, ensure that every request includes the token in the `Authorization` header using a cookie, rather than storing it in `localStorage`.",
  "summary": "Flask and React are a great pairing: fast to build, flexible, and easy to deploy. But that same speed means security often gets pushed to \"later,\" and later usually means after something breaks. I work as a secure software engineer, and these five mistakes keep showing up in tutorials, side projects, and early-stage apps. None of them are exotic. All of them are fixable in a few lines. 1.…",
  "key_points": [
    "Validate user input against schema using Pydantic",
    "Store JWTs in HttpOnly, Secure, SameSite cookies",
    "Include token in Authorization header on React frontend"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}