feat: add azdextutil shared library for azd extension framework#20
Merged
feat: add azdextutil shared library for azd extension framework#20
Conversation
Shared utilities for azd extension development: - GenerateMetadataFromCobra: lightweight metadata generation from Cobra commands - NewMetadataCommand: standard hidden metadata command factory - RateLimiter: token bucket rate limiter for MCP tools - ValidatePath/ValidateShellName: security validation helpers - SetupTracingFromEnv/GetTraceContext: distributed tracing context propagation - GetProjectDir: safe project directory resolution Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Deprecate SetupTracingFromEnv/GetTraceContext -> use azdext.NewContext() - Deprecate GenerateMetadataFromCobra/NewMetadataCommand -> use azdext.GenerateExtensionMetadata() - Deprecate azdextutil.ValidatePath -> use security.ValidatePathWithinBases() - Add security.ValidatePathWithinBases() with base directory containment - All deprecated functions kept for backwards compatibility Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- GetArgsMap: extract arguments from MCP tool requests - GetStringParam: safely extract string parameters - MarshalToolResult: JSON marshal to MCP result Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- EvalSymlinks on base directories for consistent comparison with resolved target path - Add security warning to deprecated ValidatePath about silent symlink error handling Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- SanitizeScriptName now blocks quotes, backslash, and comment char - MarshalToolResult returns actual error instead of nil on marshal failure Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix deprecated type comments to start with type name per ST1021 - Check error return of fmt.Fprintln in metadata.go - Check error return of os.WriteFile in security_test.go Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
==========================================
+ Coverage 73.14% 73.63% +0.49%
==========================================
Files 39 44 +5
Lines 3649 3827 +178
==========================================
+ Hits 2669 2818 +149
- Misses 796 810 +14
- Partials 184 199 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Fix ValidatePathWithinBases to resolve parent symlinks for non-existent files (handles macOS /var -> /private/var) - Run gofmt on azdextutil package (CRLF -> LF) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Adds the
azdextutilpackage - a shared utility library that all azd extensions use for common extension framework functionality. Also hardens thesecuritypackage with symlink-safe path validation.What's New
azdextutil/package (NEW)NewRateLimiter()/CheckRateLimit()for MCP tool rate limitingGetArgsMap(),GetStringParam(),MarshalToolResult()for MCP tool handlersValidateShellName(),GetProjectDir()SetupTracingFromEnv()-> useazdext.NewContext(),GenerateMetadataFromCobra()-> useazdext.GenerateExtensionMetadata(),ValidatePath()-> usesecurity.ValidatePathWithinBases()security/package (ENHANCED)ValidatePathWithinBases()- New function that resolves symlinks on BOTH the target path AND base directories (prevents symlink bypass)SanitizeScriptName()- Added missing shell metacharacters: quotes, backslash, hashTest Coverage
azdextutil: 90.2% coverage (12 tests)security: 82.1% coverageChanges