{"id":28264,"date":"2021-07-07T15:25:27","date_gmt":"2021-07-07T15:25:27","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=28264"},"modified":"2021-07-07T15:25:27","modified_gmt":"2021-07-07T15:25:27","slug":"code-scanning-with-github-actions","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/code-scanning-with-github-actions\/","title":{"rendered":"Code Scanning C++ with GitHub Actions"},"content":{"rendered":"<p>Last year, GitHub <a href=\"https:\/\/github.blog\/2020-09-30-code-scanning-is-now-available\/\">released code scanning<\/a>, which enables developers to incorporate security checks into their CI\/CD environment and developer workflow. This post demonstrates the basics of using CodeQL, the analysis engine behind code scanning, with GitHub Actions.<\/p>\n<h2>What is CodeQL?<\/h2>\n<p><a href=\"https:\/\/codeql.github.com\/docs\/codeql-overview\/\">CodeQL<\/a> is an analysis engine that automates security checks by running queries against a database generated from your codebase. This CodeQL database is created during the build process and represents the source code in relational form. By default, code scanning runs standard CodeQL queries written by GitHub researchers and the community, but you can also author your own custom queries.<\/p>\n<p>The default set includes queries such as \u201cPointer overflow check\u201d, \u201cPotentially overflowing call to snprintf\u201d, \u201cUncontrolled format string\u201d, and more.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-28274\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture.jpg\" alt=\"Image Capture\" width=\"2366\" height=\"1274\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture.jpg 2366w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture-300x162.jpg 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture-1024x551.jpg 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture-768x414.jpg 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture-1536x827.jpg 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture-2048x1103.jpg 2048w\" sizes=\"(max-width: 2366px) 100vw, 2366px\" \/><\/a><\/p>\n<h2>Setting up CodeQL with GitHub Actions<\/h2>\n<p>Code scanning with CodeQL is free for public repositories, and is part of GitHub Advanced Security for GitHub Enterprise. Here are instructions for the quick, <a href=\"https:\/\/docs.github.com\/en\/code-security\/secure-coding\/automatically-scanning-your-code-for-vulnerabilities-and-errors\/setting-up-code-scanning-for-a-repository\">4-click setup process<\/a>. Alternatively, I\u2019ve included a gif of the steps below:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/codeqlsetup.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-28267\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/codeqlsetup.gif\" alt=\"Image codeqlsetup\" width=\"2080\" height=\"1342\" \/><\/a><\/p>\n<p>And just like that, you\u2019re off to the races! The default CodeQL analysis workflow is configured to analyze your code each time you push a chance or raise a pull request against the default branch. This means code scanning automatically happened after I committed the new file directly to the main branch.<\/p>\n<p>You can <a href=\"https:\/\/docs.github.com\/en\/code-security\/secure-coding\/automatically-scanning-your-code-for-vulnerabilities-and-errors\/setting-up-code-scanning-for-a-repository#viewing-the-logging-output-from-code-scanning\">view the logging output<\/a> of the scan under the Actions tab, and you can <a href=\"https:\/\/docs.github.com\/en\/code-security\/secure-coding\/automatically-scanning-your-code-for-vulnerabilities-and-errors\/managing-code-scanning-alerts-for-your-repository\">view\/manage any code scanning alerts<\/a> under the Security tab.<\/p>\n<h2>Baselining<\/h2>\n<p>Sometimes, especially for large legacy codebases, the number of alerts can be overwhelming. For that reason, CodeQL only shows new\/fixed alerts in pull requests. If you want to manage existing alerts, you can do so in the \u201cCode scanning alerts\u201d section under the \u201cSecurity\u201d tab.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-scaled.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-28275\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-scaled.jpg\" alt=\"Image Capture2\" width=\"2500\" height=\"1138\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-scaled.jpg 2500w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-300x137.jpg 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-1024x466.jpg 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-768x350.jpg 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-1536x699.jpg 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/06\/Capture2-2048x932.jpg 2048w\" sizes=\"(max-width: 2500px) 100vw, 2500px\" \/><\/a><\/p>\n<p>It\u2019s important to understand the distinction between <em>Dismiss <\/em>and <em>Delete<\/em>. One key distinction is that by <em>Dismissing <\/em>an alert, the same code won\u2019t regenerate the alert. By <em>Deleting<\/em> an alert, the same code will generate the same alert the next time it is scanned. In the case that you want to bulk-dismiss alerts, you can do this from the summary of alerts (after filtering the list to whatever set of alerts you\u2019d like to dismiss).<\/p>\n<h2>Feedback<\/h2>\n<p>This post just scratches the surface of code scanning in your CI\/CD environment. Once you get the understand the basics, you may choose to author your own custom CodeQL queries or adjust the frequency of scanning. We hope you give code scanning with GitHub Actions a try, and we look forward to your feedback.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year, GitHub released code scanning, which enables developers to incorporate security checks into their CI\/CD environment and developer workflow. This post demonstrates the basics of using CodeQL, the analysis engine behind code scanning, with GitHub Actions. What is CodeQL? CodeQL is an analysis engine that automates security checks by running queries against a database [&hellip;]<\/p>\n","protected":false},"author":329,"featured_media":28274,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-28264","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>Last year, GitHub released code scanning, which enables developers to incorporate security checks into their CI\/CD environment and developer workflow. This post demonstrates the basics of using CodeQL, the analysis engine behind code scanning, with GitHub Actions. What is CodeQL? CodeQL is an analysis engine that automates security checks by running queries against a database [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/28264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/329"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=28264"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/28264\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/28274"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=28264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=28264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=28264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}