-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add beego framework support #91
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
base: main
Are you sure you want to change the base?
Conversation
Reviewer's GuideAdds Beego v2 web framework support to the Go taint engine by introducing a dedicated entrypoint-collection checker, wiring it into the entrypoint interpretation flow, and extending union value handling to support primitive units used by Beego routing APIs. Sequence diagram for Beego entrypoint collection and taint source markingsequenceDiagram
actor Dev
participant Analyzer
participant CheckerManager
participant BeegoChecker as BeegoEntrypointCollectChecker
participant RouteRegistry as processedRouteRegistry
participant Controller
participant IntroduceTaint
Dev->>Analyzer: analyze main entryPoint
Analyzer->>CheckerManager: checkAtSymbolInterpretOfEntryPointBefore(analyzer, scope, node, state, info)
CheckerManager->>BeegoChecker: triggerAtSymbolInterpretOfEntryPointAfter(analyzer, scope, node, state, info)
BeegoChecker-->>RouteRegistry: clear when entryPoint.functionName == main
Dev->>Analyzer: code uses webHttpServer.Router(path, controller, methods)
Analyzer->>CheckerManager: triggerAtFunctionCallBefore(analyzer, scope, node, state, info)
CheckerManager->>BeegoChecker: triggerAtFunctionCallBefore(analyzer, scope, node, state, info)
BeegoChecker->>BeegoChecker: handleHttpServerMethod(analyzer, scope, state, name, argvalues)
BeegoChecker->>BeegoChecker: flattenUnionValues(argvalues slice 2)
BeegoChecker->>Controller: read controller.field[methodName]
BeegoChecker->>RouteRegistry: check hash in processedRouteRegistry
alt not processed
BeegoChecker->>Analyzer: completeEntryPoint(controllerMethodVal)
Analyzer-->>Analyzer: entryPoints.push(entryPoint)
BeegoChecker->>RouteRegistry: add hash
end
Dev->>Analyzer: controller method calls ctx.GetString()
Analyzer->>CheckerManager: triggerAtFunctionCallAfter(analyzer, scope, node, state, info)
CheckerManager->>BeegoChecker: triggerAtFunctionCallAfter(analyzer, scope, node, state, info)
BeegoChecker-->>IntroduceTaint: markTaintSource(ret, meta) when directTaintSourceFuncs contains method
Dev->>Analyzer: controller method accesses this.Ctx
Analyzer->>CheckerManager: triggerAtMemberAccess(analyzer, scope, node, state, info)
CheckerManager->>BeegoChecker: triggerAtMemberAccess(analyzer, scope, node, state, info)
BeegoChecker-->>IntroduceTaint: markTaintSource(res, meta) when MemberAccess Ctx from controller
Class diagram for the new Beego entrypoint collection checkerclassDiagram
class Checker {
+resultManager
+name
+triggerAtFunctionCallBefore(analyzer, scope, node, state, info)
+triggerAtFunctionCallAfter(analyzer, scope, node, state, info)
+triggerAtMemberAccess(analyzer, scope, node, state, info)
+triggerAtAssignment(analyzer, scope, node, state, info)
+triggerAtSymbolInterpretOfEntryPointAfter(analyzer, scope, node, state, info)
}
class BeegoEntrypointCollectChecker {
+BeegoEntrypointCollectChecker(resultManager)
+triggerAtFunctionCallBefore(analyzer, scope, node, state, info)
+triggerAtFunctionCallAfter(analyzer, scope, node, state, info)
+triggerAtMemberAccess(analyzer, scope, node, state, info)
+triggerAtAssignment(analyzer, scope, node, state, info)
+triggerAtSymbolInterpretOfEntryPointAfter(analyzer, scope, node, state, info)
+isControllerMethod(name, value) bool
+handleHttpServerMethod(analyzer, scope, state, name, argvalues)
+handleNamespaceMethod(analyzer, scope, state, name, argvalues)
+handleErrorControllerArgVal(analyzer, controllerArgVal)
+handleAutoControllerArgVal(analyzer, controllerArgVal)
}
Checker <|-- BeegoEntrypointCollectChecker
class Analyzer {
+entryPoints
+processInstruction(scope, node, state)
+processAndCallFuncDef(scope, fdef, fclos, state)
+buildNewObject(cdef, args, thisVal, state, extra, scope)
}
class Unit {
+vtype
+literalType
+value
+ast
+field
+fdef
+__this
}
class IntroduceTaint {
+markTaintSource(target, meta)
}
class processedRouteRegistry {
}
class controllerQids {
}
BeegoEntrypointCollectChecker --> Analyzer : uses
BeegoEntrypointCollectChecker --> Unit : analyzes
BeegoEntrypointCollectChecker --> IntroduceTaint : calls
BeegoEntrypointCollectChecker --> processedRouteRegistry : tracks
BeegoEntrypointCollectChecker --> controllerQids : tracks
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @CrackTC, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the static analysis engine's capabilities by integrating comprehensive support for the Beego web framework. It enables the system to accurately identify and analyze application entry points and potential user-controlled data sources within Beego-based Go projects. This enhancement improves the precision and coverage of security and quality checks for applications leveraging the Beego framework, ensuring a more thorough and effective analysis of Go codebases. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Hey there - I've reviewed your changes - here's some feedback:
- The logic that checks
ast.loc, computes a hash, deduplicates viaprocessedRouteRegistry, updatescontrollerQids, callscompleteEntryPoint, and pushes toanalyzer.entryPointsis repeated in several places; consider extracting this into a small helper to avoid duplication and keep the behavior consistent. controllerQidsis a module-level set that is never cleared (unlikeprocessedRouteRegistryintriggerAtSymbolInterpretOfEntryPointAfter); if analyses can span multiple entry points or runs in the same process, consider resetting this as well to avoid stale state leaking across analyses.- Several paths (e.g., in
handleErrorControllerArgValandhandleAutoControllerArgVal) assumev.fieldexists on units returned fromflattenUnionValues; add a type guard or null check aroundv.fieldto avoid potential runtime errors when encountering unexpected unit shapes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic that checks `ast.loc`, computes a hash, deduplicates via `processedRouteRegistry`, updates `controllerQids`, calls `completeEntryPoint`, and pushes to `analyzer.entryPoints` is repeated in several places; consider extracting this into a small helper to avoid duplication and keep the behavior consistent.
- `controllerQids` is a module-level set that is never cleared (unlike `processedRouteRegistry` in `triggerAtSymbolInterpretOfEntryPointAfter`); if analyses can span multiple entry points or runs in the same process, consider resetting this as well to avoid stale state leaking across analyses.
- Several paths (e.g., in `handleErrorControllerArgVal` and `handleAutoControllerArgVal`) assume `v.field` exists on units returned from `flattenUnionValues`; add a type guard or null check around `v.field` to avoid potential runtime errors when encountering unexpected unit shapes.
## Individual Comments
### Comment 1
<location> `src/checker/taint/go/beego-entrypoint-collect-checker.ts:156-157` </location>
<code_context>
+ * @param state
+ * @param info
+ */
+ triggerAtSymbolInterpretOfEntryPointAfter(analyzer: any, scope: any, node: any, state: any, info: any) {
+ if (info?.entryPoint.functionName === 'main') processedRouteRegistry.clear()
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Use optional chaining for `entryPoint` as well to avoid runtime errors when it is absent.
`info?.entryPoint.functionName` will still throw if `info` exists but `info.entryPoint` is `null` or `undefined`. Use full optional chaining (e.g. `if (info?.entryPoint?.functionName === 'main')`) to make this access safe.
</issue_to_address>
### Comment 2
<location> `src/checker/taint/go/beego-entrypoint-collect-checker.ts:341-343` </location>
<code_context>
+ * @param analyzer
+ * @param controllerArgVal
+ */
+ handleErrorControllerArgVal(analyzer: any, controllerArgVal: Unit) {
+ flattenUnionValues([controllerArgVal])
+ .flatMap((v) => Object.entries(v.field))
+ .filter(([fieldName, fieldVal]) => this.isControllerMethod(fieldName, fieldVal) && fieldName.startsWith('Error'))
+ .map(([, controllerMethodVal]) => controllerMethodVal as Unit)
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Guard access to `v.field` to avoid crashes when the value has no `field` map.
In both `handleErrorControllerArgVal` and `handleAutoControllerArgVal`, the result of `flattenUnionValues` is passed straight into `Object.entries(v.field)`. If any value lacks a `field` property or it’s `null`, this will throw. Please add a guard, e.g. `.flatMap((v) => v.field ? Object.entries(v.field) : [])`, so these helpers safely skip such values.
Suggested implementation:
```typescript
handleErrorControllerArgVal(analyzer: any, controllerArgVal: Unit) {
flattenUnionValues([controllerArgVal])
.flatMap((v) => (v && v.field ? Object.entries(v.field) : []))
.filter(([fieldName, fieldVal]) => this.isControllerMethod(fieldName, fieldVal) && fieldName.startsWith('Error'))
.map(([, controllerMethodVal]) => controllerMethodVal as Unit)
.forEach((controllerMethodVal) => {
```
`).
Here are the edits:
```xml
<file_operations>
<file_operation operation="edit" file_path="src/checker/taint/go/beego-entrypoint-collect-checker.ts">
<<<<<<< SEARCH
handleErrorControllerArgVal(analyzer: any, controllerArgVal: Unit) {
flattenUnionValues([controllerArgVal])
.flatMap((v) => Object.entries(v.field))
.filter(([fieldName, fieldVal]) => this.isControllerMethod(fieldName, fieldVal) && fieldName.startsWith('Error'))
.map(([, controllerMethodVal]) => controllerMethodVal as Unit)
.forEach((controllerMethodVal) => {
=======
handleErrorControllerArgVal(analyzer: any, controllerArgVal: Unit) {
flattenUnionValues([controllerArgVal])
.flatMap((v) => (v && v.field ? Object.entries(v.field) : []))
.filter(([fieldName, fieldVal]) => this.isControllerMethod(fieldName, fieldVal) && fieldName.startsWith('Error'))
.map(([, controllerMethodVal]) => controllerMethodVal as Unit)
.forEach((controllerMethodVal) => {
>>>>>>> REPLACE
</file_operation>
</file_operations>
<additional_changes>
Search in the same file (`src/checker/taint/go/beego-entrypoint-collect-checker.ts`) for the implementation of `handleAutoControllerArgVal`.
Wherever you see:
.flatMap((v) => Object.entries(v.field))
update it to:
.flatMap((v) => (v && v.field ? Object.entries(v.field) : []))
This will ensure both helpers safely skip values lacking a `field` property or having `field === null`, avoiding runtime crashes.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Code Review
This pull request introduces support for the Beego web framework in the Go taint analysis. It correctly integrates the new Beego entrypoint collection checker into the existing checker configurations. The new checker identifies Beego HTTP entry points and tracks request-derived inputs as taint sources, which is a valuable addition to the analysis capabilities. The changes to util.ts and go-analyzer.ts are also appropriate for propagating entry point metadata and handling primitive values.
However, there are several areas that could be improved for correctness, maintainability, and robustness, particularly within the new beego-entrypoint-collect-checker.ts file. These include addressing global state, refining method identification logic, and improving code structure and error handling.
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.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on December 27
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Summary by Sourcery
Add Beego web framework support to the Go taint analysis by recognizing Beego HTTP entry points and request-derived inputs as taint sources.
New Features:
Enhancements:
Note
Introduce Beego framework support by adding an entrypoint/taint checker, updating configs, enhancing util flattening, and passing entryPoint context to analyzer hooks.
checker/taint/go/beego-entrypoint-collect-checker.ts:AutoRouter/AutoPrefix,Router/NSRouter,Ctrl*/NSCtrl*,Include/NSInclude,Handler, filters, namespaces,ErrorController,BConfig.RecoverFunc).Bind,Ctx, and input getters likeGetString,GetInt, etc.).beego-entrypoint-collect-checkerinresource/checker/checker-config.json.taint-flow-golang-defaultpack inresource/checker/checker-pack-config.json.{ entryPoint }tocheckAtSymbolInterpretOfEntryPointBeforeingo-analyzer.ts.flattenUnionValuesnow supportsprimitiveunits inchecker/taint/go/util.ts.Written by Cursor Bugbot for commit 94e63fe. This will update automatically on new commits. Configure here.