refactor: deduplicate shared code between daemon and libcrust#112
Merged
refactor: deduplicate shared code between daemon and libcrust#112
Conversation
d9a20da to
e1bfbec
Compare
Extract two shared functions that were copy-pasted between daemon (security/manager_init.go) and libcrust (libcrust.go, storage.go): - plugin.InitDefaultRegistry() β creates pool, registry, registers sandbox - telemetry.SeedMetrics(ctx, storage) β loads 24h event counts into memory
e1bfbec to
adf1031
Compare
cyyever
added a commit
that referenced
this pull request
Mar 20, 2026
Extract two shared functions that were copy-pasted between daemon (security/manager_init.go) and libcrust (libcrust.go, storage.go): - plugin.InitDefaultRegistry() β creates pool, registry, registers sandbox - telemetry.SeedMetrics(ctx, storage) β loads 24h event counts into memory
cyyever
added a commit
that referenced
this pull request
Mar 20, 2026
Extract two shared functions that were copy-pasted between daemon (security/manager_init.go) and libcrust (libcrust.go, storage.go): - plugin.InitDefaultRegistry() β creates pool, registry, registers sandbox - telemetry.SeedMetrics(ctx, storage) β loads 24h event counts into memory
cyyever
added a commit
that referenced
this pull request
Mar 20, 2026
Extract two shared functions that were copy-pasted between daemon (security/manager_init.go) and libcrust (libcrust.go, storage.go): - plugin.InitDefaultRegistry() β creates pool, registry, registers sandbox - telemetry.SeedMetrics(ctx, storage) β loads 24h event counts into memory
cyyever
added a commit
that referenced
this pull request
Mar 20, 2026
* refactor: deduplicate plugin init and metrics seeding (#112) Extract two shared functions that were copy-pasted between daemon (security/manager_init.go) and libcrust (libcrust.go, storage.go): - plugin.InitDefaultRegistry() β creates pool, registry, registers sandbox - telemetry.SeedMetrics(ctx, storage) β loads 24h event counts into memory * fix: suppress CodeQL false positives, add filepath.Clean defense-in-depth - secure_unix.go: add filepath.Clean() before os.WriteFile/MkdirAll/OpenFile (callers already validate, this satisfies CodeQL taint analysis) - loader.go: add filepath.Clean() before os.Lstat (path already validated by ValidatePathInDirectory above) - codeql-config.yml: exclude sse_buffer.go from XSS analysis (SSE writes JSON protocol frames to text/event-stream, not HTML) * docs: remove stale gin references from comments and docs * fix: use filepath.Rel for CodeQL-recognized path sanitization Replace custom HasPathPrefix with filepath.Rel as primary containment check in ValidatePathInDirectory. CodeQL recognizes filepath.Rel as a path injection sanitizer, resolving alerts on loader.go and callers (SecureWriteFile, os.Remove). Keep HasPathPrefix as secondary defense for case-insensitive filesystem bypasses. * fix: resolve remaining CodeQL alerts at root cause - sse_buffer.go: set Content-Type text/event-stream and use io.Writer (not http.ResponseWriter) to prevent reflected-xss false positive - extractor_net.go: add explicit n>255 bounds check adjacent to byte() cast so CodeQL recognizes the guard - dlp.go: add (?:^|\b) anchor to Slack webhook regex to satisfy missing-regexp-anchor rule - Remove codeql-config.yml paths-ignore now that root causes are fixed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminate code duplication between CLI daemon and libcrust. Fix daemon PostChecker bug.
Commit 1: Plugin init + metrics seeding
plugin.InitDefaultRegistry()β shared plugin pool + registry + sandbox registrationtelemetry.SeedMetrics(ctx, storage)β shared metrics restore from SQLiteCommit 2: Headers + streaming
libcrust.CopyHeaders()β RFC 7230 compliant (libcrust had naive version)libcrust.StripHopByHopHeaders()β RFC 7230 compliant (libcrust was missing Host/Origin/Referer)libcrust.ForceNonStreaming()β with stream_options deletion (httpproxy was missing this)libcrust.IsHopByHop()β shared hop-by-hop lookupCommit 3: PostChecker bug fix + shared wiring
SetPostChecker()β plugins were dead code in daemon pathlibcrust.WirePluginPostChecker(engine, registry)β shared function (no build tag)manager_init.gonow calls itInit()delegates to same functionparseBlockMode()now delegates totypes.ParseBlockMode()Shared files in
pkg/libcrust/(no build tag)headers.goCopyHeaders,StripHopByHopHeaders,IsHopByHopstreaming.goForceNonStreamingplugins.goWirePluginPostChecker,buildPluginRequestImpact
stream_optionsdeletionTest plan
go build ./...passesCGO_ENABLED=0 go build -tags libcrust ./pkg/libcrust/passesgo test -race -shortpasses for all affected packages