mrheinen / lophiid

A distributed honeypot for monitoring large scale web attacks
GNU General Public License v2.0
6 stars 1 forks source link

Update main from dev #61

Closed mrheinen closed 1 week ago

mrheinen commented 1 week ago

User description

Fixes for the API CLI, add limit for LLM prompt input size, Add metabase rule and more


PR Type

Enhancement, Bug fix


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
8 files
backend_main.go
Add input size limit to LLM responder                                       

cmd/backend/backend_main.go
  • Updated NewLLMResponder call to include MaxInputCharacters parameter
  • +1/-1     
    main.go
    Implement input length limit in LLM CLI                                   

    cmd/llm/main.go
  • Added maxInputLength flag
  • Updated NewLLMResponder call to include maxInputLength parameter
  • +2/-1     
    cli.go
    Extend ContentRule struct with new fields                               

    pkg/api/cli/cli.go
  • Added new fields to ContentRule struct: Responder, ResponderDecoder,
    and Enabled
  • +11/-8   
    llm_responder.go
    Implement input length limit in LLM responder                       

    pkg/backend/responder/llm_responder.go
  • Added maxInputChars field to LLMResponder struct
  • Implemented input length check in Respond method
  • +11/-3   
    goja.go
    Add logging capability to JavaScript util                               

    pkg/javascript/goja.go - Added `Log` field of type `Logger` to `Util` struct
    +1/-0     
    logger.go
    Implement JavaScript-accessible logger                                     

    pkg/javascript/logger.go
  • Implemented new Logger struct with methods for different log levels
  • Added caching of log messages for JavaScript access
  • +55/-0   
    RequestView.vue
    Add raw response display to RequestView                                   

    ui/src/components/container/RequestView.vue - Added new `RawHttpCard` component for displaying raw response data
    +3/-0     
    RuleForm.vue
    Add content link in RuleForm                                                         

    ui/src/components/container/RuleForm.vue - Added external link icon next to content ID input
    +4/-0     
    Configuration changes
    4 files
    config.go
    Add MaxInputCharacters to Responder config                             

    pkg/backend/config.go - Added `MaxInputCharacters` field to Responder config struct
    +1/-0     
    backend-config.yaml
    Add rate limiter and max input config                                       

    config/backend-config.yaml
  • Added ratelimiter configuration
  • Added max_input_characters to responder configuration
  • +8/-0     
    BUILD.bazel
    Add Bazel test rule for responder                                               

    pkg/backend/responder/BUILD.bazel - Added `go_test` rule for responder tests
    +8/-1     
    BUILD.bazel
    Update Bazel build for JavaScript logger                                 

    pkg/javascript/BUILD.bazel - Added `logger.go` to the list of source files
    +1/-0     
    Tests
    1 files
    llm_responder_test.go
    Add unit tests for LLM responder                                                 

    pkg/backend/responder/llm_responder_test.go
  • Added new test file for LLM responder
  • Implemented tests for input length limit and unknown responder type
  • +49/-0   
    Documentation
    1 files
    SCRIPTING.md
    Update responder usage example in documentation                   

    SCRIPTING.md
  • Updated example usage of util.responder.Respond to use
    template.getData()
  • +1/-1     

    ๐Ÿ’ก PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    codiumai-pr-agent-pro[bot] commented 1 week ago

    PR Reviewer Guide ๐Ÿ”

    Here are some key observations to aid the review process:

    โฑ๏ธ Estimated effort to review: 3 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšชโšช
    ๐Ÿงช PR contains tests
    ๐Ÿ”’ No security concerns identified
    โšก Recommended focus areas for review

    Input Validation
    The input length check is implemented, but there's no validation for the 'resType' parameter. Consider adding a check for valid responder types. Potential Memory Issue
    The Logger struct keeps appending messages to the Messages slice without any limit. This could lead to excessive memory usage over time. Consider implementing a maximum capacity or a circular buffer. UI Improvement
    The external link icon has been added, but it might be beneficial to add a tooltip or some form of user feedback to explain what the icon does when clicked.
    github-actions[bot] commented 1 week ago

    Failed to generate code suggestions for PR

    codiumai-pr-agent-pro[bot] commented 1 week ago

    PR Code Suggestions โœจ

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Implement a method to limit the number of stored messages to prevent unbounded growth ___ **Consider adding a method to limit the number of stored messages to prevent unbounded
    growth of the Messages slice.** [pkg/javascript/logger.go [37-40]](https://github.com/mrheinen/lophiid/pull/61/files#diff-dd845176907d183704d542be5276501e8c4b47bfc354fe20160faa48370e18d5R37-R40) ```diff func (l *Logger) Info(message string) { - l.Messages = append(l.Messages, message) + l.addMessage(message) slog.Info(message) } +func (l *Logger) addMessage(message string) { + if len(l.Messages) >= l.capacity { + l.Messages = l.Messages[1:] + } + l.Messages = append(l.Messages, message) +} + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: This suggestion addresses a potential memory leak issue by limiting the growth of the Messages slice, which is crucial for long-running applications and overall system stability.
    8
    Use a computed property for dynamic URL generation to improve code organization and maintainability ___ **Consider using a computed property for the content link URL to improve readability
    and maintainability.** [ui/src/components/container/RuleForm.vue [67-69]](https://github.com/mrheinen/lophiid/pull/61/files#diff-cbf1e6db434afc9f525cacca672df1403bb3b7a5cd4e20d9352ec60f7a847eafR67-R69) ```diff - + +// In the Githubissues.
  • Githubissues is a development platform for aggregating issues.