diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 000000000..665fde68c --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +# This repository is maintained by: +@es-codeql \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..6dc4b1210 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +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 both within project spaces and in public spaces +when an individual is representing the project or its community. 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 . 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 [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..543d3c4cb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +## Contributing + +[fork]: https://github.com/advanced-security/codeql-sap-js/fork +[pr]: https://github.com/advanced-security/codeql-sap-js/compare +[style]: https://github.com/github/codeql/blob/main/docs/ql-style-guide.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.txt). + +Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. + +## Submitting a pull request + +1. [Fork][fork] and clone the repository +1. Configure and install the [CodeQL CLI](https://github.com/github/codeql-cli-binaries/releases) specified in the `qlt.conf.json` file +1. Create a new branch: `git checkout -b my-branch-name` +1. Make your changes +1. Make sure the QL tests pass on your machine +1. Ensure the files are appropriately formatted (QL files should be formatted with `codeql query format`) +1. Push to your fork and [submit a draft pull request](https://github.com/advanced-security/codeql-sap-js/compare). Make sure to select **Create Draft Pull Request**. +7. Address failed checks, if any. +8. Mark the [pull request ready for review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review). +9. Pat your self 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 [CodeQL style guide][style]. +- Write good tests. +- 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) diff --git a/LICENSE b/LICENSE.txt similarity index 95% rename from LICENSE rename to LICENSE.txt index 0d381fb9d..28a50fa22 100644 --- a/LICENSE +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Advanced Security +Copyright 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 diff --git a/README.md b/README.md index 81f7f23c7..70dcd7887 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,15 @@ codeql database analyze --format=sarif-latest --output= \ advanced-security/javascript-sap-async-xsjs-queries ``` -## License +## License + +This project is licensed under the terms of the MIT open source license. Please refer to [MIT](LICENSE.txt) for the full terms. + +## Maintainers + +See [CODEOWNERS](CODEOWNERS) + +## Support + +See [SUPPORT](SUPPORT.md) -The code in this repository is licensed under the [MIT License](LICENSE) by [GitHub](https://github.com). diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 000000000..149361255 --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,13 @@ +# Support + +## How to file issues and get help + +This project uses GitHub issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue. + +For help or questions about using this project, please raise an issue. + +CodeQL for SAP JavaScript frameworks is under active development and maintained by GitHub staff AND THE COMMUNITY. We will do our best to respond to support, feature requests, and community questions in a timely manner. + +## GitHub Support Policy + +Support for this project is limited to the resources listed above. diff --git a/javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/RemoteFlowSources.qll b/javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/RemoteFlowSources.qll index 6669b8ffb..f427bc9b3 100644 --- a/javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/RemoteFlowSources.qll +++ b/javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/RemoteFlowSources.qll @@ -58,10 +58,6 @@ class ODataServiceModel extends UI5ExternalModel { override string getSourceType() { result = "ODataServiceModel" } ODataServiceModel() { - /* - * e.g. this.getView().setModel(this.getOwnerComponent().getModel("booking_nobatch")) - */ - exists(MethodCallNode setModelCall, CustomController controller | /* * 1. This flows from a DF node corresponding to the parent component's model to the `this.setModel` call diff --git a/scripts/ExtractJSDoc.ql b/scripts/ExtractJSDoc.ql deleted file mode 100644 index 5c6598897..000000000 --- a/scripts/ExtractJSDoc.ql +++ /dev/null @@ -1,4 +0,0 @@ -import FortifyTag - -from FortifySinkTag tag -select tag.getYamlRow() diff --git a/scripts/FortifyTag.qll b/scripts/FortifyTag.qll deleted file mode 100644 index 729c46b9d..000000000 --- a/scripts/FortifyTag.qll +++ /dev/null @@ -1,292 +0,0 @@ -import javascript - -abstract class FortifyTag extends JSDocTag { - FortifyTag() { - exists(JSDoc doc | - this = doc.getATagByTitle("SecSource") or - this = doc.getATagByTitle("SecSink") or - this = doc.getATagByTitle("SecValidate") or - this = doc.getATagByTitle("SecPassthrough") - ) - } - - string getFortifySpec() { - result = this.getDescription().splitAt("\n", 0).regexpCapture(".*(\\{.+\\}).*", 1) - } - - string getFortifySpecContents() { result = this.getFortifySpec().regexpCapture("\\{(.+)\\}", 1) } - - DocumentedObject getDocumentedObject() { result.getDocumentation() = this.getJSDocComment() } - - abstract string getYamlRow(); -} - -class FortifySourceTag extends FortifyTag { - FortifySourceTag() { exists(JSDoc doc | this = doc.getATagByTitle("SecSource")) } - - string getOutSpec() { - if this.getFortifySpecContents().splitAt("|", 0) = "return" - then result = "ReturnValue" - else result = "" - } - - string getFlags() { - if not exists(this.getFortifySpecContents().splitAt("|", 1)) - then result = "" - else result = this.getFortifySpecContents().splitAt("|", 1) - } - - predicate isJQuery() { this.getFile().getStem().prefix(6) = "jquery" } - - predicate hasNameTag() { exists(this.getJSDocComment().getATagByTitle("name")) } - - string getNameTag() { result = this.getJSDocComment().getATagByTitle("name").getName() } - - string getModuleName() { - /* "~/openui5/src/sap.ui.core/src/jquery.sap.sjax.js" */ - if this.isJQuery() or this.hasNameTag() - then result = "global" - else - /* "~/openui5/src/sap.ui.core/src/sap/base/util/UriParameters.js" */ - result = - this.getFile() - .getAbsolutePath() - .regexpCapture(".*(sap\\/[a-zA-Z]+\\/.*)", 1) - .regexpCapture("(.*)\\.js", 1) - } - - string getAPILangString() { - if this.isJQuery() - then - if this.hasNameTag() - then - result = - this.getNameTag().replaceAll("#", ".").regexpReplaceAll("([a-zA-Z]+)", "Member[$1]") + "." - + this.getOutSpec() - else - result = - this.getDocumentedObject().getExprString().regexpReplaceAll("([a-zA-Z]+)", "Member[$1]") + - "." + this.getOutSpec() - else - exists(DocumentedObject object | object = this.getDocumentedObject() | - if object.isNotAMethod() - then result = "Instance.Member[" + object.getExprString() + "]" - else result = "Instance.Member[" + object.getExprString() + "]" + "." + this.getOutSpec() - ) - } - - override string getYamlRow() { - result = - "[\"" + this.getModuleName() + "\", " + "\"" + this.getAPILangString() + "\", " + "\"" + - this.getFlags() + "\"" + "]" - } -} - -class FortifySinkTag extends FortifyTag { - FortifySinkTag() { exists(JSDoc doc | this = doc.getATagByTitle("SecSink")) } - - string getInSpec() { - if this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").regexpMatch(".*\\*.*") - then result = this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").replaceAll("*", "0..") - else - if count(this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").toInt()) = 1 - then result = this.getFortifySpecContents().splitAt("|", 0).splitAt(" ") - else - result = - min(this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").toInt()) + ".." + - max(this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").toInt()) - } - - string getFlags() { - if not exists(this.getFortifySpecContents().splitAt("|", 1)) - then result = "" - else result = this.getFortifySpecContents().splitAt("|", 1) - } - - predicate hasNameTag() { exists(this.getJSDocComment().getATagByTitle("name")) } - - string getNameTag() { result = this.getJSDocComment().getATagByTitle("name").getName() } - - predicate isJQuery() { this.getFile().getStem().prefix(6) = "jquery" } - - string getModuleName() { - /* "~/openui5/src/sap.ui.core/src/jquery.sap.sjax.js" */ - if this.isJQuery() or this.hasNameTag() - then result = "global" - else - /* "~/openui5/src/sap.ui.core/src/sap/base/util/UriParameters.js" */ - result = - this.getFile() - .getAbsolutePath() - .regexpCapture(".*(sap\\/[a-zA-Z]+\\/.*)", 1) - .regexpCapture("(.*)\\.js", 1) - } - - string getAPILangString() { - if this.isJQuery() - then - if this.hasNameTag() - then - result = - this.getNameTag().replaceAll("#", ".").regexpReplaceAll("([a-zA-Z]+)", "Member[$1]") + - ".Argument[" + this.getInSpec() + "]" - else - result = - this.getDocumentedObject().getExprString().regexpReplaceAll("([a-zA-Z]+)", "Member[$1]") + - ".Argument[" + this.getInSpec() + "]" - else - exists(DocumentedObject object | object = this.getDocumentedObject() | - if object.isNotAMethod() - then result = "Instance.Member[" + object.getExprString() + "]" - else - result = - "Instance.Member[" + object.getExprString() + "].Argument[" + this.getInSpec() + "]" - ) - } - - override string getYamlRow() { - result = - "[\"" + this.getModuleName() + "\", " + "\"" + this.getAPILangString() + "\", " + "\"" + - this.getFlags() + "\"" + "]" - } -} - -class FortifyValidateTag extends FortifyTag { - FortifyValidateTag() { exists(JSDoc doc | this = doc.getATagByTitle("SecValidate")) } - - string getInSpec() { - result = this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").replaceAll("*", "0..") - } - - string getOutSpec() { - if this.getFortifySpecContents().splitAt("|", 1) = "return" - then result = "ReturnValue" - else result = "" - } - - string getFlags() { - if not exists(this.getFortifySpecContents().splitAt("|", 2)) - then result = "" - else result = this.getFortifySpecContents().splitAt("|", 2) - } - - predicate hasNameTag() { exists(this.getJSDocComment().getATagByTitle("name")) } - - string getNameTag() { result = this.getJSDocComment().getATagByTitle("name").getName() } - - predicate isJQuery() { this.getFile().getStem().prefix(6) = "jquery" } - - string getModuleName() { - /* "~/openui5/src/sap.ui.core/src/jquery.sap.sjax.js" */ - if this.isJQuery() - then result = "global" - else - /* "~/openui5/src/sap.ui.core/src/sap/base/util/UriParameters.js" */ - result = - this.getFile() - .getAbsolutePath() - .regexpCapture(".*(sap/[a-zA-Z]+/.*)", 1) - .regexpCapture("(.*)\\.js", 1) - } - - string getPathString() { - if this.isJQuery() - then - result = - this.getDocumentedObject().getExprString().regexpReplaceAll("([a-zA-Z]+)", "Member[$1]") - else result = "" - } - - string getAPILangStringInSpec() { result = "Argument[" + this.getInSpec() + "]" } - - string getAPILangStringOutSpec() { result = this.getOutSpec() } - - override string getYamlRow() { - result = - "[\"" + this.getModuleName() + "\", " + "\"" + this.getPathString() + "\", " + "\"" + - this.getAPILangStringInSpec() + "\", " + "\"" + this.getAPILangStringOutSpec() + "\", " + - "\"taint\"]" - } -} - -class FortifyPassthroughTag extends FortifyTag { - FortifyPassthroughTag() { exists(JSDoc doc | this = doc.getATagByTitle("SecPassthrough")) } - - string getInSpec() { - result = this.getFortifySpecContents().splitAt("|", 0).splitAt(" ").replaceAll("*", "0..") - } - - string getOutSpec() { - if this.getFortifySpecContents().splitAt("|", 1) = "return" - then result = "ReturnValue" - else result = "" - } - - string getFlags() { - if not exists(this.getFortifySpecContents().splitAt("|", 2)) - then result = "" - else result = this.getFortifySpecContents().splitAt("|", 2) - } - - predicate isJQuery() { this.getFile().getStem().prefix(6) = "jquery" } - - string getModuleName() { - /* "~/openui5/src/sap.ui.core/src/jquery.sap.sjax.js" */ - if this.isJQuery() - then result = "global" - else - /* "~/openui5/src/sap.ui.core/src/sap/base/util/UriParameters.js" */ - result = - this.getFile() - .getAbsolutePath() - .regexpCapture(".*(sap/[a-zA-Z]+/.*)", 1) - .regexpCapture("(.*)\\.js", 1) - } - - string getPathString() { - if this.isJQuery() - then - result = - this.getDocumentedObject().getExprString().regexpReplaceAll("([a-zA-Z]+)", "Member[$1]") - else result = "" - } - - string getAPILangStringInSpec() { result = "Argument[" + this.getInSpec() + "]" } - - string getAPILangStringOutSpec() { result = this.getOutSpec() } - - override string getYamlRow() { - result = - "[\"" + this.getModuleName() + "\", " + "\"" + this.getPathString() + "\", " + "\"" + - this.getAPILangStringInSpec() + "\", " + "\"" + this.getAPILangStringOutSpec() + "\", " + - "\"taint\"]" - } -} - -class DocumentedObject extends Expr { - DocumentedObject() { - this instanceof AssignExpr - or - this instanceof VarDecl - or - this instanceof ObjectExpr and this.getParent() instanceof Property - } - - string getExprString() { - this instanceof AssignExpr and - exists(Expr lhs | lhs = this.(AssignExpr).getLhs() | - ( - if lhs.(DotExpr).getBase().toString() = "jQuery.sap" - then result = lhs.(DotExpr).getQualifiedName() - else result = lhs.(DotExpr).getPropertyName() - ) - ) - or - this instanceof ObjectExpr and - result = this.getParent().(Property).getAChildExpr().(Label).getName() - or - this instanceof VarDecl and result = this.(VarDecl).getName() - } - - predicate isNotAMethod() { this instanceof ObjectExpr } -} diff --git a/scripts/qlpack.yml b/scripts/qlpack.yml deleted file mode 100644 index f91b03b86..000000000 --- a/scripts/qlpack.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -library: false -warnOnImplicitThis: false -name: advanced-security/jsdoc-extraction -version: 0.0.1 -dependencies: - codeql/javascript-all: "^2.0.0"