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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025

      I may have found the ultimate monitor for conferencing and productivity, but it has a few weaknesses

      June 2, 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

      May report 2025

      June 2, 2025
      Recent

      May report 2025

      June 2, 2025

      Write more reliable JavaScript with optional chaining

      June 2, 2025

      Deploying a Scalable Next.js App on Vercel – A Step-by-Step Guide

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

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025
      Recent

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»GitHub for Beginners: Security best practices with GitHub Copilot

    GitHub for Beginners: Security best practices with GitHub Copilot

    April 14, 2025

    Welcome to the next episode in our GitHub for Beginners series, where we are diving into the world of GitHub Copilot. This is our fourth episode, and we’ve already talked about Copilot in general, some of its essential features, and how to write good prompts to get the most out of Copilot. We have all the previous episodes on our blog and available as videos.

    Today we’re going to be talking about security. Everyone knows that you should make your code secure and no one wants to be responsible for any potential hacks. But did you know that GitHub Copilot can help you with some security best practices? We’ll show you how you can use it and other tools to help make your projects more secure from day one.

    For the demos in this series, we’re using GitHub Copilot in Visual Studio Code.

    Copilot is available in other IDEs, but the available functionality may vary depending on your environment.

    Let’s talk security

    Most security teams, through no fault of their own, don’t have sufficient time or resources to properly secure their companies’ code. That makes developers the first line of defense, which is tough because many developers don’t have enough formal security training to do the job properly. For those who don’t have the proper training, they’re often forced to learn these skills on the job.

    Fortunately, GitHub is here to help—both with GitHub Copilot and a bunch of security tools you can use for free if you’re building open source code.

    Copilot to the rescue

    GitHub Copilot doesn’t just know how to write code; it also understands how to make code more secure. But it isn’t perfect, so you have to know what to ask. You also shouldn’t rely on it as your only security tool.

    Let’s start with a simple example.

    Let’s say you’re working with a SQL database using an INSERT statement to add data. Now, you may have heard of SQL injection. If you haven’t, or if you need a refresher, that’s where someone sneaks in a malicious command through a regular text field, like a comment box or name input. This could be a command like DROP TABLE, which could delete your entire database.

    One way to protect your code is to ask GitHub Copilot to regenerate it. Delete the code that uses the INSERT command and write a clear comment explaining what you want to do. For example, you could insert the following comment:

    /*
    insert from cart using a parameterized query:
    mail, product_name, user_name, product_id, address, phone, ship_date, price" and get a Copilot suggestion
    */
    

    Copilot will suggest a safer, parameterized query—because security shouldn’t be guesswork.

    Once you’ve added that comment, if GitHub Copilot is enabled in your IDE, it’ll suggest some code for you. Before accepting the code, be sure to review what Copilot wrote—it’s a helpful assistant, but it’s your job to verify and validate. Once you’ve verified the output, hit Tab to accept the suggestion.


    https://github.blog/wp-content/uploads/2025/04/sanitize_input.mp4#t=0.001

    Now, what if you don’t want to delete your existing code? You may have a chunk of code that you want to check. In this case, you can ask Copilot to look through your code and fix it. To do this, highlight the code you want to review, open Copilot Chat and ask “are there any vulnerabilities in this function?”

    https://github.blog/wp-content/uploads/2025/04/vulns_in_function.mp4#t=0.001

    If you want to expand the scope, you could select the whole file or use @workspace in the Copilot Chat window. Using @workspace tells Copilot to look at all the files in your workspace, not just the ones that you currently have open. A great prompt to try is: “@workspace what’s the attack surface?” That’s a fancy way of asking how someone might try to attack this project.

    Copilot will scan your code and offer suggestions it can find. These might include individual changes to the code or certain packages you might want to consider adding to the project to make it more secure.

    You can take this a step further by using the slash command /fix, to get suggestions for improving overall code quality and efficiency.

    Don’t forget that you can always follow up with more detailed questions after Copilot gives you a response or makes a suggestion. You can ask Copilot questions like:

    • “What does this vulnerability mean?”
    • “Can you suggest a safer way to do this?”

    For more sample prompts, check out our Copilot Chat Cookbook. The section on Finding vulnerabilities is particularly appropriate for this topic.

    Dedicated security tools

    While Github Copilot is powerful, it’s not meant to replace all your security tools. This is partly because Copilot is a generalist, not a specialist. It can’t always see the full context of your production environment. Built-to-purpose security tools can take other factors into account, such as your compiler, your environment variables, and your deployment method.

    Fortunately, GitHub has a number of free security offerings for open source maintainers. This means you can use them at no cost on your public repositories. Let’s take a look at some of them.

    Dependabot
    If you’ve been working on code in a public GitHub repository, you may have noticed a pull request from someone called dependabot. That’s GitHub’s tool that checks to make sure your dependencies are vulnerability-free and up-to-date.

    A pull request from Dependabot.

    To enable or disable Dependabot, click the Settings tab for your repository. Scroll down and click Code security in the left-hand menu. In this menu, there is an entire section for Dependabot. You can enable or disable alerts as well as automatic updates.

    Code scanning & CodeQL
    The next section in a public repository is Code scanning. If you don’t see this section, it likely means you’re working in a private repository. Code scanning will automatically detect common vulnerabilities and coding errors, such as the SQL injection vulnerability we talked about at the beginning of this post. We highly recommend you enable CodeQL analysis.

    A screenshot showing the window where you can enable CodeQL analysis.

    To do so, click the Set up button, and select Default from the menu that appears. Then click the green Enable CodeQL button at the bottom of the pop up window. This enables GitHub to look for pattern-based vulnerabilities in your code. This happens automatically when you commit new code to your repository, when you make pull requests, and as a periodic scan. If GitHub finds a new problem, it will send you a notification so you can fix it.

    Copilot Autofix
    If you want to have Copilot automatically suggest fixes to these vulnerabilities, enable Copilot Autofix. It can be found on the Code security page, under the button to Enable CodeQL. With this enabled, GitHub will run Copilot when it discovers a problem, and it will create a pull request with a suggested solution provided by Copilot. Once you review the solution, you’ll have the option to accept the pull request, eliminating the need for you to manually run Copilot to generate a possible solution.

    https://github.blog/wp-content/uploads/2025/04/copilot_autofix.mp4#t=0.001

    Secret scanning
    The next security tool we want to point out is secret scanning. You can find the option for secret scanning at the bottom of the Code security page. By enabling secret scanning, GitHub scans your code to look for possible exposed secrets, such as passwords or security tokens. You never want these directly embedded in your code because of the security risk. With Push protection enabled, GitHub will proactively block any new secrets from being committed to your GitHub-hosted code.

    A screenshot showing how to enable Push protection.

    There are several other features that we don’t have time to explore here. If you’d like to read more on your own, check out our documentation about GitHub security features and our quickstart for securing your repository.

    Your next steps

    Security is an incredibly deep topic, and we don’t expect you to be an expert. For now, remember these three things:

    1. Ask Copilot to find and fix vulnerabilities. This might be as simple as running /fix in Copilot Chat, or it could be more detailed such as selecting some code and asking Copilot to check it for vulnerabilities.
    2. Ask Copilot for more details when problems are found. It’s important to understand the solution, both to make sure you can verify its work and also as a learning opportunity to help you in the future.
    3. Enable Dependabot, code scanning, and secret scanning. These tools in the Code security settings will be useful for sending you alerts when there are potential problems you want to be aware of. And remember that Copilot can help you fix them!

    Don’t forget that you can use GitHub Copilot for free! If you have any questions, pop them in the GitHub Community thread, and we’ll be sure to respond. Join us for the next part in this series, where we’ll learn how to build a REST API with Copilot.

    Happy coding!

    The post GitHub for Beginners: Security best practices with GitHub Copilot appeared first on The GitHub Blog.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleNext Level CSS Styling for Cursors
    Next Article Ubuntu 25.10 is Officially Named ‘Questing Quokka’

    Related Posts

    News & Updates

    The Alters: Release date, mechanics, and everything else you need to know

    June 2, 2025
    News & Updates

    I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Qiulong Ransomware Group Targets Brazilian Surgeon Dr. Willian Segalin, Citing Privacy Concerns

    Development

    A single Dune: Awakening map will be almost ten times the size of Conan Exiles, where you can “meet hundreds of players”

    Development

    This $449 Lenovo convertible laptop gets up to 13 hours of battery life

    News & Updates

    Microsoft keeps backporting Windows 11 24H2 features to Windows 11 23H2

    Development
    GetResponse

    Highlights

    ANN vs CNN vs RNN: Understanding the Difference

    January 19, 2025

    In the fast-changing world of artificial intelligence, neural networks play a crucial role in driving new progress. As a key component of AI Services, deep learning—a subset of machine learning—enables various types of neural networks to learn from vast datasets. This empowers them to tackle complex tasks once thought to be exclusively human capabilities. This
    The post ANN vs CNN vs RNN: Understanding the Difference appeared first on Codoid.

    How CSS Container Style Queries Enhance Web Design

    June 16, 2024

    Microsoft risks EU fine up to 10% of its global annual turnover over Teams’ bundling practice

    June 27, 2024

    Doris is a modern data warehouse for real-time analytics

    April 26, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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