-
Notifications
You must be signed in to change notification settings - Fork 0
fix: rule condition review and updates (#152) #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5cc84c7
ffa2d69
f286c9e
98991f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -295,12 +295,12 @@ const detachedInstanceCheck: RuleCheckFn = (node, context) => { | |||||||||||||||||
| // Heuristic: Frame with a name that looks like it came from a component | ||||||||||||||||||
| if (node.type !== "FRAME") return null; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Check if there's a component in the file with a similar name | ||||||||||||||||||
| // Check if there's a component in the file with a matching name (word boundary) | ||||||||||||||||||
| const components = context.file.components; | ||||||||||||||||||
| const nodeName = node.name.toLowerCase(); | ||||||||||||||||||
|
|
||||||||||||||||||
| for (const [, component] of Object.entries(components)) { | ||||||||||||||||||
| if (nodeName.includes(component.name.toLowerCase())) { | ||||||||||||||||||
| const pattern = new RegExp(`\\b${component.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`); | ||||||||||||||||||
| if (pattern.test(node.name)) { | ||||||||||||||||||
|
Comment on lines
301
to
+303
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Regex escaping is correct; static analysis ReDoS warning is a false positive here. The escape pattern correctly covers all standard regex metacharacters ( One edge case worth noting: 📝 Optional: Add brief comment explaining the escaping rationale for (const [, component] of Object.entries(components)) {
+ // Escape regex metacharacters; resulting pattern is pure literals within word boundaries (no ReDoS risk)
const pattern = new RegExp(`\\b${component.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
if (pattern.test(node.name)) {📝 Committable suggestion
Suggested change
🧰 Tools🪛 ast-grep (0.41.1)[warning] 301-301: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns. (regexp-from-variable) 🤖 Prompt for AI Agents |
||||||||||||||||||
| // This frame might be a detached instance of this component | ||||||||||||||||||
| return { | ||||||||||||||||||
| ruleId: detachedInstanceDef.id, | ||||||||||||||||||
|
|
||||||||||||||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 44
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 308
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 1308
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 755
🏁 Script executed:
# Read the detached-instance test file to check test coverage cat -n src/core/rules/component/detached-instance.test.tsRepository: let-sunny/canicode
Length of output: 2398
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 2015
🏁 Script executed:
Repository: let-sunny/canicode
Length of output: 1281
Clarify case-sensitivity approach and add test coverage for this rule.
The implementation uses case-sensitive matching, but this choice is neither documented in tests nor documented in comments. More importantly, the
missing-componentrule in the same file uses case-insensitive matching (lines 125, 139-141), creating an inconsistency.The test suite has no coverage for case-sensitivity variations (e.g., frame "button" vs component "Button"). Add a test case demonstrating the case-sensitive behavior to make the design choice explicit, or align both rules on a consistent approach.
🧰 Tools
🪛 ast-grep (0.41.1)
[warning] 301-301: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(
\\b${component.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b)Note: [CWE-1333] Inefficient Regular Expression Complexity [REFERENCES]
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- https://cwe.mitre.org/data/definitions/1333.html
(regexp-from-variable)
🤖 Prompt for AI Agents