Skip to content

Conversation

@CrackTC
Copy link
Collaborator

@CrackTC CrackTC commented Dec 3, 2025

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:

  • Introduce a Beego entrypoint collection checker that discovers controller methods, filters, and handlers as HTTP entry points in Go applications.
  • Track Beego controller context and input APIs as taint sources for request-derived data in Go taint analysis.

Enhancements:

  • Propagate entry point metadata into entrypoint checkers and extend Go taint utilities to flatten primitive values needed for Beego routing analysis.

Note

Introduce Beego framework support by adding an entrypoint/taint checker, updating configs, enhancing util flattening, and passing entryPoint context to analyzer hooks.

  • Go Taint Analysis (Beego support):
    • New checker checker/taint/go/beego-entrypoint-collect-checker.ts:
      • Collects entrypoints from Beego APIs (AutoRouter/AutoPrefix, Router/NSRouter, Ctrl*/NSCtrl*, Include/NSInclude, Handler, filters, namespaces, ErrorController, BConfig.RecoverFunc).
      • Marks taint sources from controller methods and inputs (Bind, Ctx, and input getters like GetString, GetInt, etc.).
  • Config:
    • Register beego-entrypoint-collect-checker in resource/checker/checker-config.json.
    • Include it in taint-flow-golang-default pack in resource/checker/checker-pack-config.json.
  • Analyzer:
    • Pass { entryPoint } to checkAtSymbolInterpretOfEntryPointBefore in go-analyzer.ts.
  • Utils:
    • flattenUnionValues now supports primitive units in checker/taint/go/util.ts.

Written by Cursor Bugbot for commit 94e63fe. This will update automatically on new commits. Configure here.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 3, 2025

Reviewer's Guide

Adds 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 marking

sequenceDiagram
  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
Loading

Class diagram for the new Beego entrypoint collection checker

classDiagram
  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
Loading

File-Level Changes

Change Details Files
Wire entry-point metadata into pre-entrypoint checker invocation so new checkers can access the current entry point.
  • Modify GoAnalyzer to pass an entryPoint object as part of the info argument when invoking checkAtSymbolInterpretOfEntryPointBefore
  • Keep existing call sites and parameters otherwise unchanged
src/engine/analyzer/golang/common/go-analyzer.ts
Extend taint utility union flattening to support primitive units, which are needed when processing Beego router arguments.
  • Include 'primitive' in the set of supported vtypes in flattenUnionValues so string literals and other primitives are preserved rather than causing an error
src/checker/taint/go/util.ts
Introduce a Beego-specific entrypoint collection and taint source checker that detects Beego routing/filters/controllers and registers corresponding entry points and taint sources.
  • Add BeegoEntrypointCollectChecker implementing pre/post function-call, member-access, assignment, and entrypoint hooks to discover controller methods and filter handlers as entry points
  • Track processed Beego route/controller locations to avoid duplicate entrypoint registration and maintain a set of controller QIDs used to recognize controller context
  • Handle web.HttpServer and web.Namespace APIs (e.g., AutoRouter/Router/Include/CtrlXxx/Filter/Cond/Handler/ErrorController) to resolve controller methods, error handlers, and filters to concrete function values
  • Mark Beego request-related APIs (Ctx, Bind, GetString/GetInt/etc.) as taint sources with kind 'GO_INPUT' to feed into the taint engine
  • Reset Beego route tracking when the main entry point is interpreted to scope per-program analysis
src/checker/taint/go/beego-entrypoint-collect-checker.ts
Register the new Beego checker in the checker configuration so it participates in analysis (details not shown in diff snippet).
  • Update checker-config and checker-pack-config JSON files to include the beego-entrypoint-collect-checker module
resource/checker/checker-config.json
resource/checker/checker-pack-config.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • New Beego Framework Support: Introduced a new checker, beego-entrypoint-collect-checker, to specifically identify entry points and potential taint sources within applications built using the Beego Go web framework.
  • Comprehensive Entry Point Detection: The new checker implements detailed logic to recognize various Beego routing mechanisms, including HttpServer methods (e.g., AutoRouter, InsertFilter, Router, Get, Post), Namespace methods, and controller methods, ensuring broad coverage for Beego applications.
  • Taint Source Identification: Specific Beego methods that commonly handle user input, such as GetBool, GetString, GetFile, and Bind, are now explicitly marked as taint sources to track data flow from external inputs.
  • Configuration Updates: The system's checker configurations (checker-config.json and checker-pack-config.json) have been updated to include and enable the new Beego entry point collection checker.
  • Analyzer Context Enhancement: The GoAnalyzer was modified to pass more contextual information, specifically the entryPoint object, to checkers during the checkAtSymbolInterpretOfEntryPointBefore hook, allowing for more informed analysis.
  • Utility Function Improvement: The flattenUnionValues utility function in src/checker/taint/go/util.ts was updated to correctly handle primitive types, improving its robustness.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a 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 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link

@cursor cursor bot left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant