Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix(api): percent-decode path parameters before use (#3682)
Kyle Mendellc469305cdacf
diff --git a/backend/internal/bootstrap/router_bootstrap.go b/backend/internal/bootstrap/router_bootstrap.goindex ffa2fbee0..5a725c24a 100644--- a/backend/internal/bootstrap/router_bootstrap.go+++ b/backend/internal/bootstrap/router_bootstrap.go@@ -176,12 +176,25 @@ type RouterParams struct {TunnelRegistry *edge.TunnelRegistry}+// newEchoInternal builds the Echo instance with path parameter values+// percent-decoded before they reach handlers (RFC 3986 §6.2.2.2); route+// matching still happens on the escaped path, so an encoded "/" cannot+// change which route matches.+func newEchoInternal() *echo.Echo {+ return echo.NewWithConfig(echo.Config{+ Router: echo.NewRouter(echo.RouterConfig{+ AllowOverwritingRoute: true,+ UnescapePathParamValues: true,+ }),+ })+}+func newRouter(p RouterParams) (*echo.Echo, *edge.TunnelServer) {ctx := p.Contextcfg := p.Configdeps := p.HandlerDeps- e := echo.New()+ e := newEchoInternal()trustedProxyNets := parseTrustedProxyCIDRsInternal(cfg.TrustedProxies)if cfg.TrustedProxies != "" && len(trustedProxyNets) == 0 {diff --git a/backend/internal/bootstrap/router_bootstrap_test.go b/backend/internal/bootstrap/router_bootstrap_test.goindex d55d1d4ea..cdbdef8ab 100644--- a/backend/internal/bootstrap/router_bootstrap_test.go+++ b/backend/internal/bootstrap/router_bootstrap_test.go@@ -1,16 +1,49 @@package bootstrapimport (+ "context""net"+ "net/http""net/http/httptest""testing"+ "github.com/danielgtaylor/huma/v2"+ "github.com/danielgtaylor/huma/v2/adapters/humaecho""github.com/getarcaneapp/arcane/backend/v2/pkg/utils/cookie""github.com/labstack/echo/v5""github.com/stretchr/testify/assert""github.com/stretchr/testify/require")+func TestNewEchoInternal_DecodesPathParams(t *testing.T) {+ router := newEchoInternal()+ api := humaecho.NewWithGroup(router, router.Group("/api"), huma.DefaultConfig("test", "1.0.0"))++ var got string+ huma.Register(api, huma.Operation{+ OperationID: "get-image",+ Method: http.MethodGet,+ Path: "/environments/{id}/images/{imageId}",+ }, func(_ context.Context, input *struct {+ ID string `path:"id"`+ ImageID string `path:"imageId"`+ }) (*struct{}, error) {+ got = input.ImageID+ return nil, nil+ })++ // RFC 3986 §6.2.2.2: these are all the same URI and must resolve identically.+ for _, segment := range []string{"sha256:abc", "sha256%3Aabc", "%73ha256:abc"} {+ got = ""+ req := httptest.NewRequest(http.MethodGet, "/api/environments/0/images/"+segment, nil)+ rec := httptest.NewRecorder()+ router.ServeHTTP(rec, req)++ require.Equal(t, http.StatusNoContent, rec.Code, "segment %q", segment)+ require.Equal(t, "sha256:abc", got, "segment %q", segment)+ }+}+func TestSecureCookieContextMiddleware_TrustGating(t *testing.T) {_, loopback, err := net.ParseCIDR("127.0.0.0/8")diff --git a/backend/internal/common/errors.go b/backend/internal/common/errors.goindex 4dde67cd2..ac28c08c6 100644--- a/backend/internal/common/errors.go+++ b/backend/internal/common/errors.go@@ -103,6 +103,7 @@ var (ErrEnvironmentConnectionTestFailed = Classify(ErrBadRequest, errors.Sentinel("Environment connection test failed"))ErrUnsafeRemoteURL = Classify(ErrBadRequest, errors.Sentinel("Remote URL is not allowed"))ErrImageScanInProgress = Classify(ErrConflict, errors.Sentinel("an image update check is already in progress"))+ ErrVulnerabilityScanNotFound = Classify(ErrNotFound, errors.Sentinel("Vulnerability scan not found"))ErrInvalidNotificationPayloadTemplate = Classify(ErrValidation, errors.Sentinel("invalid generic webhook payload template"))ErrRedeployAfterSyncFailed = errors.Sentinel("redeploy failed")ErrGitOpsSyncProjectBindingBroken = errors.Sentinel("GitOps sync project binding broken")diff --git a/backend/internal/image/handler.go b/backend/internal/image/handler.goindex 727088d2d..5350aafde 100644--- a/backend/internal/image/handler.go+++ b/backend/internal/image/handler.go@@ -7,7 +7,6 @@ import ("fmt""io""net/http"- "net/url""strings"activitytypes "github.com/getarcaneapp/arcane/types/v2/activity"@@ -408,13 +407,9 @@ func (h *ImageHandler) GetImage(ctx context.Context, input *GetImageInput) (*Get// GetImageAttestations returns in-toto attestation statements attached to an image.func (h *ImageHandler) GetImageAttestations(ctx context.Context, input *GetImageAttestationsInput) (*GetImageAttestationsOutput, error) {- imageName, err := url.PathUnescape(input.ImageName)+ imageName, err := validateImageNameInternal(input.ImageName)if err != nil {- return nil, huma.Error400BadRequest(fmt.Sprintf("invalid image name %q", input.ImageName))- }- imageName = strings.TrimSpace(imageName)- if imageName == "" {- return nil, huma.Error400BadRequest("image name is required")+ return nil, err}if input.Platform != "" {@@ -442,7 +437,7 @@ func (h *ImageHandler) GetImageAttestations(ctx context.Context, input *GetImage// TagImage adds a repository tag to an image.func (h *ImageHandler) TagImage(ctx context.Context, input *TagImageInput) (*TagImageOutput, error) {- imageName, err := decodeImageNameInternal(input.ImageName)+ imageName, err := validateImageNameInternal(input.ImageName)if err != nil {return nil, err}@@ -469,7 +464,7 @@ func (h *ImageHandler) TagImage(ctx context.Context, input *TagImageInput) (*Tag// GetImageHistory returns Docker image layer history.func (h *ImageHandler) GetImageHistory(ctx context.Context, input *GetImageHistoryInput) (*GetImageHistoryOutput, error) {- imageName, err := decodeImageNameInternal(input.ImageName)+ imageName, err := validateImageNameInternal(input.ImageName)if err != nil {return nil, err}@@ -513,7 +508,7 @@ func (h *ImageHandler) SearchImages(ctx context.Context, input *SearchImagesInpu// ExportImage streams a Docker image tar archive.func (h *ImageHandler) ExportImage(ctx context.Context, input *ExportImageInput) (*huma.StreamResponse, error) {- imageName, err := decodeImageNameInternal(input.ImageName)+ imageName, err := validateImageNameInternal(input.ImageName)if err != nil {return nil, err}@@ -535,12 +530,8 @@ func (h *ImageHandler) ExportImage(ctx context.Context, input *ExportImageInput)}, nil}-func decodeImageNameInternal(raw string) (string, error) {- imageName, err := url.PathUnescape(raw)- if err != nil {- return "", huma.Error400BadRequest(fmt.Sprintf("invalid image name %q", raw))- }- imageName = strings.TrimSpace(imageName)+func validateImageNameInternal(raw string) (string, error) {+ imageName := strings.TrimSpace(raw)if imageName == "" {return "", huma.Error400BadRequest("image name is required")}diff --git a/backend/internal/template/handler.go b/backend/internal/template/handler.goindex 037e3f746..7ebd69117 100644--- a/backend/internal/template/handler.go+++ b/backend/internal/template/handler.go@@ -3,7 +3,6 @@ package templateimport ("context""encoding/json/v2"- "net/url""emperror.dev/errors""github.com/danielgtaylor/huma/v2"@@ -372,15 +371,7 @@ func (h *TemplateHandler) GetTemplate(ctx context.Context, input *GetTemplateInpreturn nil, huma.Error400BadRequest("Template ID is required")}- // Path parameter arrives URL-encoded (e.g. "remote%3Areg%3Aslug" for remote IDs that- // contain ':' separators). Chi/Huma do not auto-decode, so decode here before- // matching against cached / stored template IDs.- id, decodeErr := url.PathUnescape(input.ID)- if decodeErr != nil {- return nil, huma.Error400BadRequest("Template ID is required")- }-- tmpl, err := h.templateService.GetTemplate(ctx, id)+ tmpl, err := h.templateService.GetTemplate(ctx, input.ID)if err != nil {if errors.Is(err, common.ErrTemplateNotFound) {return nil, huma.Error404NotFound("Template not found")@@ -407,12 +398,7 @@ func (h *TemplateHandler) GetTemplateContent(ctx context.Context, input *GetTempreturn nil, huma.Error400BadRequest("Template ID is required")}- id, decodeErr := url.PathUnescape(input.ID)- if decodeErr != nil {- return nil, huma.Error400BadRequest("Template ID is required")- }-- contentData, err := h.templateService.GetTemplateContentWithParsedData(ctx, id)+ contentData, err := h.templateService.GetTemplateContentWithParsedData(ctx, input.ID)if err != nil {if errors.Is(err, common.ErrTemplateNotFound) {return nil, huma.Error404NotFound("Template not found")@@ -464,11 +450,6 @@ func (h *TemplateHandler) UpdateTemplate(ctx context.Context, input *UpdateTemplreturn nil, huma.Error400BadRequest("Template ID is required")}- id, decodeErr := url.PathUnescape(input.ID)- if decodeErr != nil {- return nil, huma.Error400BadRequest("Template ID is required")- }-updates := &ComposeTemplate{Name: input.Body.Name,Description: input.Body.Description,@@ -480,14 +461,14 @@ func (h *TemplateHandler) UpdateTemplate(ctx context.Context, input *UpdateTemplupdates.EnvContent = nil}- if err := h.templateService.UpdateTemplate(ctx, id, updates); err != nil {+ if err := h.templateService.UpdateTemplate(ctx, input.ID, updates); err != nil {if errors.Is(err, common.ErrTemplateNotFound) {return nil, huma.Error404NotFound("Template not found")}return nil, huma.Error500InternalServerError(errors.WithMessage(err, "Failed to update template").Error())}- updated, err := h.templateService.GetTemplate(ctx, id)+ updated, err := h.templateService.GetTemplate(ctx, input.ID)if err != nil {return nil, huma.Error500InternalServerError(errors.WithMessage(err, "Failed to get template").Error())}@@ -511,12 +492,7 @@ func (h *TemplateHandler) DeleteTemplate(ctx context.Context, input *DeleteTemplreturn nil, huma.Error400BadRequest("Template ID is required")}- id, decodeErr := url.PathUnescape(input.ID)- if decodeErr != nil {- return nil, huma.Error400BadRequest("Template ID is required")- }-- if err := h.templateService.DeleteTemplate(ctx, id); err != nil {+ if err := h.templateService.DeleteTemplate(ctx, input.ID); err != nil {if errors.Is(err, common.ErrTemplateNotFound) {return nil, huma.Error404NotFound("Template not found")}@@ -539,12 +515,7 @@ func (h *TemplateHandler) DownloadTemplate(ctx context.Context, input *DownloadTreturn nil, huma.Error400BadRequest("Template ID is required")}- id, decodeErr := url.PathUnescape(input.ID)- if decodeErr != nil {- return nil, huma.Error400BadRequest("Template ID is required")- }-- tmpl, err := h.templateService.GetTemplate(ctx, id)+ tmpl, err := h.templateService.GetTemplate(ctx, input.ID)if err != nil {if errors.Is(err, common.ErrTemplateNotFound) {return nil, huma.Error404NotFound("Template not found")diff --git a/backend/internal/vulnerability/handler.go b/backend/internal/vulnerability/handler.goindex 0dd850abb..29cea5748 100644--- a/backend/internal/vulnerability/handler.go+++ b/backend/internal/vulnerability/handler.go@@ -6,6 +6,7 @@ import ("emperror.dev/errors""github.com/danielgtaylor/huma/v2"+ "github.com/getarcaneapp/arcane/backend/v2/internal/common""github.com/getarcaneapp/arcane/backend/v2/internal/middleware""github.com/getarcaneapp/arcane/backend/v2/pkg/authz""github.com/getarcaneapp/arcane/backend/v2/pkg/utils"@@ -351,6 +352,9 @@ func (h *VulnerabilityHandler) ListImageVulnerabilities(ctx context.Context, inpitems, paginationResp, err := h.vulnerabilityService.ListVulnerabilities(ctx, input.ImageID, params)if err != nil {+ if errors.Is(err, common.ErrVulnerabilityScanNotFound) {+ return nil, huma.Error404NotFound("Vulnerability scan not found")+ }return nil, huma.Error500InternalServerError(errors.WithMessage(err, "Failed to retrieve vulnerability scan").Error())}diff --git a/backend/internal/vulnerability/service_test.go b/backend/internal/vulnerability/service_test.goindex 7969ca80b..3af44b487 100644--- a/backend/internal/vulnerability/service_test.go+++ b/backend/internal/vulnerability/service_test.go@@ -9,6 +9,9 @@ import ("testing""time"+ "emperror.dev/errors"++ "github.com/getarcaneapp/arcane/backend/v2/internal/common""github.com/getarcaneapp/arcane/backend/v2/internal/database""github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/vuln""github.com/getarcaneapp/arcane/backend/v2/pkg/pagination"@@ -134,6 +137,15 @@ func setupVulnerabilityScanTestDB(t *testing.T) *database.DB {return &database.DB{DB: db}}+func TestVulnerabilityService_ListVulnerabilities_NoScanReturnsNotFound(t *testing.T) {+ db := setupVulnerabilityScanTestDB(t)+ svc := &VulnerabilityService{db: db}++ _, _, err := svc.ListVulnerabilities(context.Background(), "sha256:unknown", pagination.QueryParams{Limit: 20})++ require.True(t, errors.Is(err, common.ErrVulnerabilityScanNotFound))+}+func TestVulnerabilityService_DeleteScanResultsByImageIDs(t *testing.T) {ctx := context.Background()db := setupVulnerabilityScanTestDB(t)diff --git a/backend/internal/vulnerability/vulnerability_query.go b/backend/internal/vulnerability/vulnerability_query.goindex d2ba3e827..501c5b67f 100644--- a/backend/internal/vulnerability/vulnerability_query.go+++ b/backend/internal/vulnerability/vulnerability_query.go@@ -13,6 +13,7 @@ import ("github.com/samber/mo""gorm.io/gorm"+ "github.com/getarcaneapp/arcane/backend/v2/internal/common""github.com/getarcaneapp/arcane/backend/v2/pkg/pagination""github.com/getarcaneapp/arcane/types/v2/vulnerability")@@ -83,10 +84,7 @@ func (s *VulnerabilityService) ListVulnerabilities(ctx context.Context, imageIDreturn nil, pagination.Response{}, errors.WrapIf(err, "failed to get scan result")}if result == nil {- if params.Limit <= 0 {- params.Limit = 20- }- return []vulnerability.Vulnerability{}, pagination.BuildResponse(0, 0, params), nil+ return nil, pagination.Response{}, common.ErrVulnerabilityScanNotFound}config := pagination.Config[vulnerability.Vulnerability]{diff --git a/frontend/package.json b/frontend/package.jsonindex 628a443d4..172a9fa52 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -1,91 +1,91 @@{- "name": "arcane-frontend",- "private": true,- "version": "2.8.1",- "type": "module",- "imports": {- "#lib/*": "./src/lib/*"- },- "scripts": {- "dev": "vp dev --port 3000 --host",- "build": "vp build",- "preview": "vp preview --port 3000",- "check": "pnpm paraglide:compile && svelte-kit sync && svelte-check-rs --tsconfig ./tsconfig.json",- "format": "vp fmt ./src",- "format:check": "vp fmt --check ./src",- "check:watch": "pnpm paraglide:compile && svelte-kit sync && svelte-check-rs --tsconfig ./tsconfig.json --watch",- "paraglide:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/lib/paraglide --strategy cookie preferredLanguage baseLocale --silent",- "fallow": "fallow"- },- "dependencies": {- "@codemirror/autocomplete": "^6.20.3",- "@codemirror/lang-javascript": "^6.2.5",- "@codemirror/lang-json": "^6.0.2",- "@codemirror/lang-markdown": "^6.5.2",- "@codemirror/lang-yaml": "^6.1.3",- "@codemirror/language": "^6.12.3",- "@codemirror/legacy-modes": "^6.5.3",- "@codemirror/lint": "^6.9.6",- "@codemirror/merge": "^6.12.2",- "@codemirror/state": "^6.6.0",- "@codemirror/view": "^6.43.8",- "@fontsource-variable/geist-mono": "^5.3.0",- "@fontsource-variable/montserrat": "^5.3.0",- "@internationalized/date": "^3.12.3",- "@lezer/highlight": "^1.2.3",- "@simplewebauthn/browser": "^13.3.0",- "@sveltejs/kit": "3.0.0-next.23",- "@tanstack/svelte-query": "^6.1.38",- "@tanstack/svelte-table": "^9.1.2",- "@tanstack/table-core": "9.1.2",- "@tanstack/virtual-core": "^3.17.7",- "@uiw/codemirror-themes": "^4.25.11",- "@xterm/addon-fit": "^0.11.0",- "@xterm/xterm": "^6.0.0",- "@xyflow/svelte": "^1.6.2",- "ajv": "^8.20.0",- "ansi-to-html": "^0.7.2",- "bits-ui": "^2.18.1",- "clsx": "^2.1.1",- "date-fns": "^4.4.0",- "embla-carousel-svelte": "^8.6.0",- "formsnap": "^2.0.1",- "ky": "^2.0.2",- "marked": "^18.0.9",- "mode-watcher": "^1.1.0",- "runed": "^0.37.1",- "svelte": "^5.56.9",- "svelte-codemirror-editor": "^2.1.0",- "svelte-easy-crop": "^5.0.1",- "svelte-sonner": "^1.2.1",- "tailwind-merge": "^3.6.0",- "tailwind-variants": "^3.3.1",- "vaul-svelte": "1.0.0-next.7",- "yaml": "^2.9.0",- "zod": "^4.4.3"- },- "devDependencies": {- "@iconify/json": "^2.2.513",- "@inlang/paraglide-js": "2.23.2",- "@sveltejs/adapter-static": "^4.0.0-next.4",- "@sveltejs/vite-plugin-svelte": "^7.3.0",- "@tailwindcss/vite": "^4.3.3",- "@tanstack/svelte-query-devtools": "^6.1.38",- "@types/node": "^26.2.0",- "@typescript/native-preview": "7.0.0-dev.20260707.2",- "fallow": "^3.17.0",- "isomorphic-dompurify": "^3.22.0",- "paneforge": "^1.0.2",- "shadcn-svelte": "^1.5.0",- "svelte-check-rs": "^0.11.0",- "svelte-toolbelt": "^0.10.6",- "sveltekit-superforms": "^2.30.2",- "tailwindcss": "^4.3.3",- "tsx": "^4.23.12",- "tw-animate-css": "^1.4.0",- "typescript": "npm:@typescript/typescript6@^6.0.2",- "unplugin-icons": "^23.0.1",- "vite": "catalog:",- "vite-plus": "catalog:"- }+ "name": "arcane-frontend",+ "private": true,+ "version": "2.8.1",+ "type": "module",+ "imports": {+ "#lib/*": "./src/lib/*"+ },+ "scripts": {+ "dev": "vp dev --port 3000 --host",+ "build": "vp build",+ "preview": "vp preview --port 3000",+ "check": "pnpm paraglide:compile && svelte-kit sync && svelte-check-rs --tsconfig ./tsconfig.json",+ "format": "vp fmt ./src",+ "format:check": "vp fmt --check ./src",+ "check:watch": "pnpm paraglide:compile && svelte-kit sync && svelte-check-rs --tsconfig ./tsconfig.json --watch",+ "paraglide:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/lib/paraglide --strategy cookie preferredLanguage baseLocale --silent",+ "fallow": "fallow"+ },+ "dependencies": {+ "@codemirror/autocomplete": "^6.20.3",+ "@codemirror/lang-javascript": "^6.2.5",+ "@codemirror/lang-json": "^6.0.2",+ "@codemirror/lang-markdown": "^6.5.2",+ "@codemirror/lang-yaml": "^6.1.3",+ "@codemirror/language": "^6.12.3",+ "@codemirror/legacy-modes": "^6.5.3",+ "@codemirror/lint": "^6.9.6",+ "@codemirror/merge": "^6.12.2",+ "@codemirror/state": "^6.6.0",+ "@codemirror/view": "^6.43.8",+ "@fontsource-variable/geist-mono": "^5.3.0",+ "@fontsource-variable/montserrat": "^5.3.0",+ "@internationalized/date": "^3.12.3",+ "@lezer/highlight": "^1.2.3",+ "@simplewebauthn/browser": "^13.3.0",+ "@sveltejs/kit": "3.0.0-next.23",+ "@tanstack/svelte-query": "^6.1.38",+ "@tanstack/svelte-table": "^9.1.2",+ "@tanstack/table-core": "9.1.2",+ "@tanstack/virtual-core": "^3.17.7",+ "@uiw/codemirror-themes": "^4.25.11",+ "@xterm/addon-fit": "^0.11.0",+ "@xterm/xterm": "^6.0.0",+ "@xyflow/svelte": "^1.6.2",+ "ajv": "^8.20.0",+ "ansi-to-html": "^0.7.2",+ "bits-ui": "^2.18.1",+ "clsx": "^2.1.1",+ "date-fns": "^4.4.0",+ "embla-carousel-svelte": "^8.6.0",+ "formsnap": "^2.0.1",+ "ky": "^2.0.2",+ "marked": "^18.0.9",+ "mode-watcher": "^1.1.0",+ "runed": "^0.37.1",+ "svelte": "^5.56.9",+ "svelte-codemirror-editor": "^2.1.0",+ "svelte-easy-crop": "^5.0.1",+ "svelte-sonner": "^1.2.1",+ "tailwind-merge": "^3.6.0",+ "tailwind-variants": "^3.3.1",+ "vaul-svelte": "1.0.0-next.7",+ "yaml": "^2.9.0",+ "zod": "^4.4.3"+ },+ "devDependencies": {+ "@iconify/json": "^2.2.513",+ "@inlang/paraglide-js": "2.23.2",+ "@sveltejs/adapter-static": "^4.0.0-next.4",+ "@sveltejs/vite-plugin-svelte": "^7.3.0",+ "@tailwindcss/vite": "^4.3.3",+ "@tanstack/svelte-query-devtools": "^6.1.38",+ "@types/node": "^26.2.0",+ "@typescript/native-preview": "7.0.0-dev.20260707.2",+ "fallow": "^3.17.0",+ "isomorphic-dompurify": "^3.22.0",+ "paneforge": "^1.0.2",+ "shadcn-svelte": "^1.5.0",+ "svelte-check-rs": "^0.11.0",+ "svelte-toolbelt": "^0.10.6",+ "sveltekit-superforms": "^2.30.2",+ "tailwindcss": "^4.3.3",+ "tsx": "^4.23.12",+ "tw-animate-css": "^1.4.0",+ "typescript": "npm:@typescript/typescript6@^6.0.2",+ "unplugin-icons": "^23.0.1",+ "vite": "catalog:",+ "vite-plus": "catalog:"+ }}