Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Top 10 Use Cases of Vibe Coding in Large-Scale Node.js Applications

      September 3, 2025

      Cloudsmith launches ML Model Registry to provide a single source of truth for AI models and datasets

      September 3, 2025

      Kong Acquires OpenMeter to Unlock AI and API Monetization for the Agentic Era

      September 3, 2025

      Microsoft Graph CLI to be retired

      September 2, 2025

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025

      ASUS built a desktop gaming PC around a mobile CPU — it’s an interesting, if flawed, idea

      September 4, 2025

      Hollow Knight: Silksong arrives on Xbox Game Pass this week — and Xbox’s September 1–7 lineup also packs in the horror. Here’s every new game.

      September 4, 2025

      The Xbox remaster that brought Gears to PlayStation just passed a huge milestone — “ending the console war” and proving the series still has serious pulling power

      September 4, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Magento (Adobe Commerce) or Optimizely Configured Commerce: Which One to Choose

      September 4, 2025
      Recent

      Magento (Adobe Commerce) or Optimizely Configured Commerce: Which One to Choose

      September 4, 2025

      Updates from N|Solid Runtime: The Best Open-Source Node.js RT Just Got Better

      September 3, 2025

      Scale Your Business with AI-Powered Solutions Built for Singapore’s Digital Economy

      September 3, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025
      Recent

      ‘Cronos: The New Dawn’ was by far my favorite experience at Gamescom 2025 — Bloober might have cooked an Xbox / PC horror masterpiece

      September 4, 2025

      ASUS built a desktop gaming PC around a mobile CPU — it’s an interesting, if flawed, idea

      September 4, 2025

      Hollow Knight: Silksong arrives on Xbox Game Pass this week — and Xbox’s September 1–7 lineup also packs in the horror. Here’s every new game.

      September 4, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»A Developer’s Guide to Protecting Personal Data: Best Practices and Tools

    A Developer’s Guide to Protecting Personal Data: Best Practices and Tools

    April 17, 2025

    Think about it: you’re sitting there enjoying your morning coffee, reading the headlines when again another data breach is making headlines. Millions of users’ personal information – gone. You can’t help but cringe as a developer at the prospect. Could it happen on your watch?

    The reality is, keeping personal data safe isn’t something you should be doing because it’s good practice it’s something you have to do. Users are trusting developers to care for their data day in and day out, and power must be wielded wisely. If you’re writing code that involves getting, processing, or storing someone’s personal data, then you should be being proactive about keeping it safe.

    So the question is: how do you safely keep personal data?

    Table of Contents

    • Know What You’re Protecting
    • Best Practices in Data Security
      • 1. Encrypt Everything
      • 2. Perform Secure Authentication
      • 3. Minimize the Data You Need to Store
      • 4. Secure APIs
      • 5. Lock Down Your Database
      • 6. Periodically Audit and Update Your Code
      • 7. Train Your Employees
      • 8. Give Users Control Over Their Data

    Know What You’re Protecting

    If you must protect information, first determine what information must be protected. It is crucial to protect sensitive information from unauthorized access to ensure data security. Below is a list of some common types of sensitive data:

    • Personally Identifiable Information (PII): name, address, phone number, email, Social Security number.

    • Financial Data: bank details, payment history, credit card number.

    • Authentication Data: password, auth tokens, API keys, security question responses.

    • Health Info: any kind of HIPAA-protected information about the health and medical history of the user.

    Once you know what information has to be rendered secure, then you can go ahead and render it secure.

    Best Practices in Data Security

    1. Encrypt Everything

    Your best protection against hacking is encryption. When data is encrypted, even if hackers have access to it, they cannot do anything with it in the absence of the decryption key.

    For stored sensitive information, use hashing with a salt, a process that turns a password into an irreversible value. This way, even if someone gains access to the stored data, the actual password isn’t exposed.

    <span class="hljs-keyword">import</span> hashlib
    <span class="hljs-keyword">import</span> os
    
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hash_password</span>(<span class="hljs-params">password</span>):</span>
        salt = os.urandom(<span class="hljs-number">32</span>)  <span class="hljs-comment"># Generate a new salt</span>
        hashed_password = hashlib.pbkdf2_hmac(<span class="hljs-string">'sha256'</span>, password.encode(<span class="hljs-string">'utf-8'</span>), salt, <span class="hljs-number">100000</span>)
        <span class="hljs-keyword">return</span> salt + hashed_password
    

    For data in transit, always use HTTPS:

    sudo certbot --nginx -d yourdomain.com
    

    This ensures data is encrypted between your server and the user. You can also reduce how often data is in transit by using edge computing. Rather than sending sensitive data to external servers, increasing risk, it allows data to be stored and processed locally.

    2. Perform Secure Authentication

    Weak authentication is an extremely critical security vulnerability.

    Authentication is the process of verifying who a user is (for example, logging in), while authorization is verifying what they’re allowed to do (for example, access admin features).

    Make sure that you:

    • Perform strong password habits.

    • Perform multi-factor authentication (MFA). MFA requires users to present two or more verification factors (for example password and one-time code from a mobile device), making it much harder for attackers to gain access.

    • Perform OAuth 2.0 or OpenID Connect third-party authentication. These are secure industry-standard protocols that allow users to authenticate via trusted platforms like Google or Facebook, reducing the need to store credentials yourself.

    Example: Here’s an authentication setup using JWT (JSON Web Tokens) in Python:

    <span class="hljs-keyword">import</span> jwt
    <span class="hljs-keyword">import</span> datetime
    
    SECRET_KEY = <span class="hljs-string">"your_secret_key"</span>
    
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">generate_token</span>(<span class="hljs-params">user_id</span>):</span>
        payload = {
            <span class="hljs-string">"user_id"</span>: user_id,
            <span class="hljs-string">"exp"</span>: datetime.datetime.utcnow() + datetime.timedelta(hours=<span class="hljs-number">1</span>)
        }
        <span class="hljs-keyword">return</span> jwt.encode(payload, SECRET_KEY, algorithm=<span class="hljs-string">'HS256'</span>)
    

    This function generates a secure token for a user. The token contains the user ID and an expiration time, and it’s signed using a secret key. Clients send this token with each request, and servers verify it to ensure the request comes from an authenticated user.

    3. Minimize the Data You Need to Store

    One of the simplest things you can do to protect personal data? Store less than you have to. Consider the following questions:

    • Do I really need to store this data?

    • How long do I really need to keep it for?

    • Can I anonymise it?

    For example, if you are going to need analytics, consider deleting personal identifiers prior to storing the data:

    <span class="hljs-keyword">const</span> anonymizeData = <span class="hljs-function">(<span class="hljs-params">user</span>) =></span> {
        <span class="hljs-keyword">return</span> {
            <span class="hljs-attr">sessionId</span>: generateRandomId(),
            <span class="hljs-attr">event</span>: user.event,
            <span class="hljs-attr">timestamp</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().toISOString()
        };
    };
    

    This JavaScript function removes identifying information (like name or email) and replaces it with a random session ID, keeping only the data necessary for analytics.

    For instance, if you manage email lists, avoid storing unnecessary subscriber data beyond what is required for communication.

    Regularly clean and scrub email lists to remove outdated or inactive addresses. Sending emails to outdated/inactive addresses can damage your domain reputation, leading to blacklisting and email deliverability issues. If you only need email addresses for temporary campaigns, consider automated deletion policies to remove old data.

    4. Secure Your APIs

    If your application is consuming other services, protect your API endpoints. You can do this by:

    • Require tokens or API keys: These act as credentials to access the API and prevent unauthorized use.

    • Implement rate limiting to deter abuse: This prevents attackers from flooding your server with too many requests.

    • Validate and sanitize all input data: This protects against injection attacks and malformed inputs.

    Here’s how you can validate API input in Node.js:

    <span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
    <span class="hljs-keyword">const</span> app = express();
    
    app.post(<span class="hljs-string">'/api/data'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =></span> {
        <span class="hljs-keyword">const</span> { name, email } = req.body;
        <span class="hljs-keyword">if</span> (!name || !email.includes(<span class="hljs-string">'@'</span>)) {
            <span class="hljs-keyword">return</span> res.status(<span class="hljs-number">400</span>).send(<span class="hljs-string">'Invalid input'</span>);
        }
        res.send(<span class="hljs-string">'Data received'</span>);
    });
    

    This ensures the API receives valid data and returns an error for incorrect input, which is a basic form of input sanitization.

    5. Lock Down Your Database

    Your database is an attack treasure trove, so lock it down:

    • Use parameterized queries to prevent SQL injection. These queries separate data from code.

    • Limit database access using role-based permissions: Only give each user or service the access it needs—no more.

    • Back up and test restoration procedures: Regular backups ensure you can recover data in the event of a breach or corruption.

    Here’s a safe way to query a database in Python:

    <span class="hljs-keyword">import</span> sqlite3
    
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_user</span>(<span class="hljs-params">email</span>):</span>
        conn = sqlite3.connect(<span class="hljs-string">'database.db'</span>)
        cursor = conn.cursor()
        cursor.execute(<span class="hljs-string">"SELECT * FROM users WHERE email = ?"</span>, (email,))
        <span class="hljs-keyword">return</span> cursor.fetchone()
    

    This example uses a parameterized query (the ? placeholder) to safely insert the email into the SQL command, protecting against injection.

    Also, never overlook how databases and internal systems might be accessed remotely. Remote access, whether for IT admins, support teams, or mobile workers, often involves logging in from unfamiliar devices—which introduces new security challenges. Tools that allow for secure, contactless logins without typing passwords or installing software on the remote machine reduce the risk of credential theft.

    You can also ensure that remote database connections, SSH access, and admin panels are protected with strong authentication, IP restrictions, and, ideally, VPN access to avoid exposing sensitive entry points to the internet.

    And remember, you don’t have to reinvent the wheel—there are powerful data protection tools available to keep your data safe from breaches and downtime. Want to know which ones stand out? Check out this guide for a breakdown of some of the best solutions.

    6. Periodically Audit and Update Your Code

    Unpatched software and outdated dependencies are essentially an open invitation to the attackers. Update your software and conduct security audits regularly.

    Perform security scans for your project:

    npm audit fix --force  # For Node.js projects
    
    pip install --upgrade package_name  <span class="hljs-comment"># For Python projects</span>
    

    These commands help find and fix known vulnerabilities in your project dependencies.

    7. Train Your Employees

    Your security is just as strong as your weakest link. If one employee handles sensitive data irresponsibly, everything else may have been for naught.

    • Standard security training: Regular sessions on topics like phishing, password security, and data handling.

    • Implement solid policies on user data handling: For instance, never download sensitive data to personal devices.

    • Establish a security-oriented culture: Encourage reporting of suspicious activity, regular internal audits, and open communication about threats.

    8. Give Users Control Over Their Data

    Transparency breeds trust. Give users control to:

    • View and download their data.

    • Terminate their account easily.

    • Make adjustments in privacy settings.

    If you are collecting data, provide an opt-out. Users must be able to protect sensitive data and be in control of what becomes of their information. This is why it is important to have a privacy policy: users need to know what data you are collecting and for what purpose. Check out this privacy policy template if you need to create one for your site.

    Final Thoughts

    Data protection isn’t just about coding well—it’s about attitude. Get in the head of an attacker for a day, minimize vulnerabilities, and put user privacy at the top of your mind.

    So the next time you’re scanning the headlines for news of the latest ginormous data breach, you can be confident that your apps are bulletproof. Be smart, continue to learn, and let’s make the internet safe—one line of secure code at a time.

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHow to Build a Public Grafana-based Solar Monitoring Dashboard in Home Assistant
    Next Article ‘It was clear that Xbox was the best option,” Towerborne developers discuss early access, the superpower of having a community, working with Microsoft, and more

    Related Posts

    Development

    How to Make Bluetooth on Android More Reliable

    September 4, 2025
    Development

    Learn Mandarin Chinese for Beginners – Full HSK 1 Level

    September 4, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-5276 – MCP Markdownify Server SSRF

    Common Vulnerabilities and Exposures (CVEs)

    Principal Financial Group increases Voice Virtual Assistant performance using Genesys, Amazon Lex, and Amazon QuickSight

    Machine Learning

    How End-to-End Testing Supports Grid Reliability for Energy Providers

    Development

    Will software and video games get affected by tariffs?

    News & Updates

    Highlights

    Detect Amazon Bedrock misconfigurations with Datadog Cloud Security

    August 30, 2025

    This post was co-written with Nick Frichette and Vijay George from Datadog.  As organizations increasingly…

    Weekly JavaScript Roundup: Friday Links 21, April 18, 2025

    April 18, 2025

    CVE-2025-22240 – GitFS Path Traversal Vulnerability

    June 13, 2025

    CVE-2025-9023 – Tenda AC7/AC18 Buffer Overflow in formSetSchedLed

    August 15, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.