From b5133280e34229743d3f869b7ebfb71b517e48b2 Mon Sep 17 00:00:00 2001 From: Aditya Sharad Date: Mon, 11 Nov 2019 19:38:28 -0800 Subject: [PATCH] CodeQL for VS Code starter: Initial commit. --- .gitmodules | 8 +++ CODE_OF_CONDUCT.md | 76 +++++++++++++++++++++ CONTRIBUTING.md | 31 +++++++++ LICENSE.md | 20 ++++++ README.md | 31 +++++++++ codeql-custom-queries-cpp/example.ql | 12 ++++ codeql-custom-queries-cpp/qlpack.yml | 3 + codeql-custom-queries-csharp/example.ql | 12 ++++ codeql-custom-queries-csharp/qlpack.yml | 3 + codeql-custom-queries-go/example.ql | 12 ++++ codeql-custom-queries-go/qlpack.yml | 3 + codeql-custom-queries-java/example.ql | 12 ++++ codeql-custom-queries-java/qlpack.yml | 3 + codeql-custom-queries-javascript/example.ql | 12 ++++ codeql-custom-queries-javascript/qlpack.yml | 3 + codeql-custom-queries-python/example.ql | 12 ++++ codeql-custom-queries-python/qlpack.yml | 3 + codeql-go | 1 + ql | 1 + vscode-codeql-starter.code-workspace | 33 +++++++++ 20 files changed, 291 insertions(+) create mode 100644 .gitmodules create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 codeql-custom-queries-cpp/example.ql create mode 100644 codeql-custom-queries-cpp/qlpack.yml create mode 100644 codeql-custom-queries-csharp/example.ql create mode 100644 codeql-custom-queries-csharp/qlpack.yml create mode 100644 codeql-custom-queries-go/example.ql create mode 100644 codeql-custom-queries-go/qlpack.yml create mode 100644 codeql-custom-queries-java/example.ql create mode 100644 codeql-custom-queries-java/qlpack.yml create mode 100644 codeql-custom-queries-javascript/example.ql create mode 100644 codeql-custom-queries-javascript/qlpack.yml create mode 100644 codeql-custom-queries-python/example.ql create mode 100644 codeql-custom-queries-python/qlpack.yml create mode 160000 codeql-go create mode 160000 ql create mode 100644 vscode-codeql-starter.code-workspace diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2d595db --- /dev/null +++ b/.gitmodules @@ -0,0 +1,8 @@ +[submodule "ql"] + path = ql + url = https://github.com/Semmle/ql.git + branch = lgtm.com +[submodule "codeql-go"] + path = codeql-go + url = ../../github/codeql-go.git + branch = lgtm.com diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..517657b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to make participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies within all project spaces, and it also applies when +an individual is representing the project or its community in public spaces. +Examples of representing a project or community include using an official +project e-mail address, posting via an official social media account, or acting +as an appointed representative at an online or offline event. Representation of +a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at opensource@github.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..409766d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,31 @@ +## Contributing + +[fork]: https://github.com/github/vscode-codeql-starter/fork +[pr]: https://github.com/github/vscode-codeql-starter/compare +[style]: https://primer.style +[code-of-conduct]: CODE_OF_CONDUCT.md + +Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. + +Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.md). + +Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. + +## Submitting a pull request + +0. [Fork][fork] and clone the repository +0. Make your change +0. Push to your fork and [submit a pull request][pr] +0. Pat yourself on the back and wait for your pull request to be reviewed and merged. + +Here are a few things you can do that will increase the likelihood of your pull request being accepted: + +- Follow the [style guide][style]. +- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. +- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). + +## Resources + +- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) +- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) +- [GitHub Help](https://help.github.com) \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..df3369d --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2019 GitHub, Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c6cab5 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# vscode-codeql-starter + +A starter workspace to use with the [CodeQL extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql). For more information, see the [`vscode-codeql` repo](https://github.com/github/vscode-codeql/). + +## Instructions + +1. Install [Visual Studio Code](https://code.visualstudio.com). +1. Install the [CodeQL extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql). +1. Clone this repository to your computer. + - Make sure to include the submodules, either by `git clone --recursive` or by `git submodule update --init --remote` after clone. + - Use `git submodule update --remote` regularly to keep the submodules up to date. +1. In VS Code, click File > Open Workspace. Select the file `vscode-codeql-starter.code-workspace` in your checkout of this repository. +1. You will see several folders open in the left sidebar: + - The `ql` folder contains the [open-source CodeQL standard libraries](https://github.com/Semmle/ql/tree/lgtm.com) for C/C++, C#, Java, JavaScript, and Python. It tracks the `lgtm.com` branch. You can run the standard queries from here, and browse the libraries. + - The `codeql-go` folder contains the [open-source CodeQL standard libraries](https://github.com/github/codeql-go/tree/lgtm.com) for Go. It tracks the `lgtm.com` branch. You can run the standard queries from here, and browse the libraries. + - The folders named `codeql-custom-queries-` are ready for you to start developing your own custom queries for each language, while using the standard libraries. There are some example queries to get you started. +1. Follow the [documentation for the CodeQL extension](https://help.semmle.com/codeql/codeql-for-vscode.html) to learn how to set up the extension, add a database and run queries against it. Have fun! + +## Contributing + +This project welcomes contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for details. + +## Reporting issues + +Issues and suggestions should be reported in the [`vscode-codeql` repo](https://github.com/github/vscode-codeql/issues/new). + +## License + +This project is [licensed](LICENSE.md) under the MIT License. + +The CodeQL extension for Visual Studio Code is [licensed](https://github.com/github/vscode-codeql/blob/master/extensions/ql-vscode/LICENSE.md) under the MIT License. The version of CodeQL used by the CodeQL extension is subject to the [CodeQL Research Terms & Conditions](https://securitylab.github.com/tools/codeql/license). diff --git a/codeql-custom-queries-cpp/example.ql b/codeql-custom-queries-cpp/example.ql new file mode 100644 index 0000000..cda6e3a --- /dev/null +++ b/codeql-custom-queries-cpp/example.ql @@ -0,0 +1,12 @@ +/** + * @name Empty block + * @kind problem + * @problem.severity warning + * @id cpp/example/empty-block + */ + +import cpp + +from Block b +where b.getNumStmt() = 0 +select b, "This is an empty block." \ No newline at end of file diff --git a/codeql-custom-queries-cpp/qlpack.yml b/codeql-custom-queries-cpp/qlpack.yml new file mode 100644 index 0000000..6b427c1 --- /dev/null +++ b/codeql-custom-queries-cpp/qlpack.yml @@ -0,0 +1,3 @@ +name: codeql-custom-queries-cpp +version: 0.0.0 +libraryPathDependencies: codeql-cpp diff --git a/codeql-custom-queries-csharp/example.ql b/codeql-custom-queries-csharp/example.ql new file mode 100644 index 0000000..f86d62a --- /dev/null +++ b/codeql-custom-queries-csharp/example.ql @@ -0,0 +1,12 @@ +/** + * @name Empty block + * @kind problem + * @problem.severity warning + * @id csharp/example/empty-block + */ + +import csharp + +from BlockStmt b +where b.getNumberOfStmts() = 0 +select b, "This is an empty block." diff --git a/codeql-custom-queries-csharp/qlpack.yml b/codeql-custom-queries-csharp/qlpack.yml new file mode 100644 index 0000000..a6be5d8 --- /dev/null +++ b/codeql-custom-queries-csharp/qlpack.yml @@ -0,0 +1,3 @@ +name: codeql-custom-queries-csharp +version: 0.0.0 +libraryPathDependencies: codeql-csharp diff --git a/codeql-custom-queries-go/example.ql b/codeql-custom-queries-go/example.ql new file mode 100644 index 0000000..c75ee67 --- /dev/null +++ b/codeql-custom-queries-go/example.ql @@ -0,0 +1,12 @@ +/** + * @name Empty block + * @kind problem + * @problem.severity warning + * @id go/example/empty-block + */ + +import go + +from BlockStmt b +where b.getNumStmt() = 0 +select b, "This is an empty block." diff --git a/codeql-custom-queries-go/qlpack.yml b/codeql-custom-queries-go/qlpack.yml new file mode 100644 index 0000000..f05cbf7 --- /dev/null +++ b/codeql-custom-queries-go/qlpack.yml @@ -0,0 +1,3 @@ +name: codeql-custom-queries-go +version: 0.0.0 +libraryPathDependencies: codeql-go diff --git a/codeql-custom-queries-java/example.ql b/codeql-custom-queries-java/example.ql new file mode 100644 index 0000000..f8908a3 --- /dev/null +++ b/codeql-custom-queries-java/example.ql @@ -0,0 +1,12 @@ +/** + * @name Empty block + * @kind problem + * @problem.severity warning + * @id java/example/empty-block + */ + +import java + +from Block b +where b.getNumStmt() = 0 +select b, "This is an empty block." \ No newline at end of file diff --git a/codeql-custom-queries-java/qlpack.yml b/codeql-custom-queries-java/qlpack.yml new file mode 100644 index 0000000..23ece19 --- /dev/null +++ b/codeql-custom-queries-java/qlpack.yml @@ -0,0 +1,3 @@ +name: codeql-custom-queries-java +version: 0.0.0 +libraryPathDependencies: codeql-java diff --git a/codeql-custom-queries-javascript/example.ql b/codeql-custom-queries-javascript/example.ql new file mode 100644 index 0000000..f4e1378 --- /dev/null +++ b/codeql-custom-queries-javascript/example.ql @@ -0,0 +1,12 @@ +/** + * @name Empty block + * @kind problem + * @problem.severity warning + * @id javascript/example/empty-block + */ + +import javascript + +from Block b +where b.getNumStmt() = 0 +select b, "This is an empty block." \ No newline at end of file diff --git a/codeql-custom-queries-javascript/qlpack.yml b/codeql-custom-queries-javascript/qlpack.yml new file mode 100644 index 0000000..3d143f9 --- /dev/null +++ b/codeql-custom-queries-javascript/qlpack.yml @@ -0,0 +1,3 @@ +name: codeql-custom-queries-javascript +version: 0.0.0 +libraryPathDependencies: codeql-javascript diff --git a/codeql-custom-queries-python/example.ql b/codeql-custom-queries-python/example.ql new file mode 100644 index 0000000..25b8ad5 --- /dev/null +++ b/codeql-custom-queries-python/example.ql @@ -0,0 +1,12 @@ +/** + * @name Empty scope + * @kind problem + * @problem.severity warning + * @id python/example/empty-scope + */ + +import python + +from Scope s +where count(s.getAStmt()) = 0 +select s, "This is an empty scope." \ No newline at end of file diff --git a/codeql-custom-queries-python/qlpack.yml b/codeql-custom-queries-python/qlpack.yml new file mode 100644 index 0000000..dc74ea1 --- /dev/null +++ b/codeql-custom-queries-python/qlpack.yml @@ -0,0 +1,3 @@ +name: codeql-custom-queries-python +version: 0.0.0 +libraryPathDependencies: codeql-python diff --git a/codeql-go b/codeql-go new file mode 160000 index 0000000..d14eb85 --- /dev/null +++ b/codeql-go @@ -0,0 +1 @@ +Subproject commit d14eb855fc88e086b587f6c9695b59eb230c79e7 diff --git a/ql b/ql new file mode 160000 index 0000000..717490b --- /dev/null +++ b/ql @@ -0,0 +1 @@ +Subproject commit 717490b6708ea28d8e724beedf4c6a47628282d2 diff --git a/vscode-codeql-starter.code-workspace b/vscode-codeql-starter.code-workspace new file mode 100644 index 0000000..eb1617e --- /dev/null +++ b/vscode-codeql-starter.code-workspace @@ -0,0 +1,33 @@ +{ + "folders": [ + { + "path": "codeql-custom-queries-cpp" + }, + { + "path": "codeql-custom-queries-csharp" + }, + { + "path": "codeql-custom-queries-go" + }, + { + "path": "codeql-custom-queries-java" + }, + { + "path": "codeql-custom-queries-javascript" + }, + { + "path": "codeql-custom-queries-python" + }, + { + "path": "codeql-go" + }, + { + "path": "ql" + } + ], + "settings": { + "ql.distribution.includePrerelease": true, + "ql.distribution.owner": "github", + "ql.distribution.repository": "codeql-cli-binaries" + } +} \ No newline at end of file