Title: isSanitizerGuard works incorrectly when the function name startwith "isValid" · Issue #17393 · github/codeql · GitHub
Open Graph Title: isSanitizerGuard works incorrectly when the function name startwith "isValid" · Issue #17393 · github/codeql
X Title: isSanitizerGuard works incorrectly when the function name startwith "isValid" · Issue #17393 · github/codeql
Description: i am try the the codeql query from https://codeql.github.com/docs/codeql-language-guides/analyzing-data-flow-in-javascript-and-typescript/ ; the code to analysis is copied from tutorial const fs = require('fs'), path = require('path'); f...
Open Graph Description: i am try the the codeql query from https://codeql.github.com/docs/codeql-language-guides/analyzing-data-flow-in-javascript-and-typescript/ ; the code to analysis is copied from tutorial const fs = ...
X Description: i am try the the codeql query from https://codeql.github.com/docs/codeql-language-guides/analyzing-data-flow-in-javascript-and-typescript/ ; the code to analysis is copied from tutorial const fs = ...
Opengraph URL: https://github.com/github/codeql/issues/17393
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"isSanitizerGuard works incorrectly when the function name startwith \"isValid\"","articleBody":"i am try the the codeql query from https://codeql.github.com/docs/codeql-language-guides/analyzing-data-flow-in-javascript-and-typescript/ ; \r\nthe code to analysis is copied from tutorial\r\n```\r\nconst fs = require('fs'),\r\n path = require('path');\r\n\r\nfunction readFileHelper(p) { // #2\r\n if (!checkPath(p)){\r\n return;\r\n }\r\n fs.readFile(p, // #4\r\n 'utf8', (err, data) =\u003e {\r\n if (err) throw err;\r\n console.log(data);\r\n });\r\n}\r\n\r\nreadFileHelper(process.argv[2]); // #1\r\n```\r\nand the query is also from tutorial\r\n```\r\n/**\r\n * @name Find usage of request.body and request.query in Express.js\r\n * @description Finds variables assigned from request.body and request.query in Express.js applications.\r\n * @kind problem\r\n * @id js/express-request-body-query\r\n */\r\nimport javascript\r\n\r\nclass CheckPathSanitizerGuard extends TaintTracking::SanitizerGuardNode, DataFlow::CallNode {\r\n CheckPathSanitizerGuard() { this.getCalleeName() = \"checkPath\" }\r\n\r\n override predicate sanitizes(boolean outcome, Expr e) {\r\n outcome = true and\r\n e = getArgument(0).asExpr()\r\n }\r\n}\r\n\r\nclass CommandLineFileNameConfiguration extends TaintTracking::Configuration {\r\n CommandLineFileNameConfiguration() { this = \"CommandLineFileNameConfiguration\" }\r\n\r\n override predicate isSource(DataFlow::Node source) {\r\n DataFlow::globalVarRef(\"process\").getAPropertyRead(\"argv\").getAPropertyRead() = source\r\n }\r\n\r\n override predicate isSink(DataFlow::Node sink) {\r\n DataFlow::moduleMember(\"fs\", \"readFile\").getACall().getArgument(0) = sink\r\n }\r\n override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode nd) {\r\n nd instanceof CheckPathSanitizerGuard\r\n }\r\n}\r\n\r\nfrom CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink\r\nwhere cfg.hasFlow(source, sink)\r\nselect source, \"12312323\" \r\n```\r\ni use command line cli (2.18.3 newest version) to get the result\r\n```\r\ncodeql database create codeqldb --language=javascript\r\ncodeql database analyze --rerun --threads 0 \u003cdir of ql\u003e/test2.ql --format=sarif-latest --output=1.sarif\r\n```\r\nIt all works fine.\r\nThen i change the ql, this line \r\n```\r\n override predicate sanitizes(boolean outcome, Expr e) {\r\n outcome = true and\r\n e = getArgument(0).asExpr()\r\n }\r\n``` \r\nto\r\n```\r\n override predicate sanitizes(boolean outcome, Expr e) {\r\n outcome = false and\r\n e = getArgument(0).asExpr()\r\n }\r\n```\r\nAs expected, it does not sanitize the output. \r\nThe wierd thing is, if i change the function name of \"checkPath\", to \"isValid\", the sanitizer works very wierd, it sanitize the output no matter outcome is true of false. code is like:\r\n```\r\nconst fs = require('fs'),\r\n path = require('path');\r\n\r\nfunction readFileHelper(p) { // #2\r\n if (!isValid(p)){\r\n return;\r\n }\r\n fs.readFile(p, // #4\r\n 'utf8', (err, data) =\u003e {\r\n if (err) throw err;\r\n console.log(data);\r\n });\r\n}\r\n\r\nreadFileHelper(process.argv[2]); // #1\r\n```\r\nql is like\r\n```\r\n/**\r\n * @name Find usage of request.body and request.query in Express.js\r\n * @description Finds variables assigned from request.body and request.query in Express.js applications.\r\n * @kind problem\r\n * @id js/express-request-body-query\r\n */\r\nimport javascript\r\n\r\nclass CheckPathSanitizerGuard extends TaintTracking::SanitizerGuardNode, DataFlow::CallNode {\r\n CheckPathSanitizerGuard() { this.getCalleeName() = \"isValid\" }\r\n\r\n override predicate sanitizes(boolean outcome, Expr e) {\r\n outcome = false and\r\n e = getArgument(0).asExpr()\r\n }\r\n}\r\n\r\nclass CommandLineFileNameConfiguration extends TaintTracking::Configuration {\r\n CommandLineFileNameConfiguration() { this = \"CommandLineFileNameConfiguration\" }\r\n\r\n override predicate isSource(DataFlow::Node source) {\r\n DataFlow::globalVarRef(\"process\").getAPropertyRead(\"argv\").getAPropertyRead() = source\r\n }\r\n\r\n override predicate isSink(DataFlow::Node sink) {\r\n DataFlow::moduleMember(\"fs\", \"readFile\").getACall().getArgument(0) = sink\r\n }\r\n override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode nd) {\r\n nd instanceof CheckPathSanitizerGuard\r\n }\r\n}\r\n\r\nfrom CommandLineFileNameConfiguration cfg, DataFlow::Node source, DataFlow::Node sink\r\nwhere cfg.hasFlow(source, sink)\r\nselect source, \"12312323\" \r\n```\r\n\r\nThe only thing changed is the function name. \"isValid\" is not some special thing in js i think. I try other function names, everything start with isValid works abnormal, like \"isValidd\" \"isValidg\", anything else works correctly, like \"isVali\"","author":{"url":"https://github.com/oicu0619","@type":"Person","name":"oicu0619"},"datePublished":"2024-09-06T02:05:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/17393/codeql/issues/17393"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c50fb222-f728-99d2-ed1f-20a7c0a09bda |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 944A:343EA:34FB4FE:47075DC:696F0EA4 |
| html-safe-nonce | 957ebb631562b596ca2654257af3f8354d8150d0e4dff529f58729a6b1acda20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDRBOjM0M0VBOjM0RkI0RkU6NDcwNzVEQzo2OTZGMEVBNCIsInZpc2l0b3JfaWQiOiI2MzA2MjQ5ODgzNDc1OTcxNzQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 312e8ee7d25aa12a3c4b97b54c803b8dee6efe64cc0a57e879be06387166c995 |
| hovercard-subject-tag | issue:2509280043 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/codeql/17393/issue_layout |
| twitter:image | https://opengraph.githubassets.com/99080030279734fc6b8b09b754fd90b09cb1eae69957336cbcbc936fa8318372/github/codeql/issues/17393 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/99080030279734fc6b8b09b754fd90b09cb1eae69957336cbcbc936fa8318372/github/codeql/issues/17393 |
| og:image:alt | i am try the the codeql query from https://codeql.github.com/docs/codeql-language-guides/analyzing-data-flow-in-javascript-and-typescript/ ; the code to analysis is copied from tutorial const fs = ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | oicu0619 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/github/codeql git https://github.com/github/codeql.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 143040428 |
| octolytics-dimension-repository_nwo | github/codeql |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143040428 |
| octolytics-dimension-repository_network_root_nwo | github/codeql |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width