Skip to content

fix(services): nil-deref in deploy EmptyBucket, dead org-discovery Errors field, ecr dedup - #1070

Merged
cristim merged 1 commit into
feat/multicloud-web-frontendfrom
fix/services-misc-cleanup
Jun 7, 2026
Merged

cristim merged 1 commit into
feat/multicloud-web-frontendfrom
fix/services-misc-cleanup

Conversation

@cristim

@cristim cristim commented Jun 7, 2026

Copy link
Copy Markdown
Member

Summary

Fixes five robustness/correctness gaps in the deploy, accounts, and iacfiles packages. Closes #1057.

07-M4 -- nil-deref panic in EmptyBucket (Medium)

internal/deploy/frontend.go: *delErr.Key and *delErr.Message were dereferenced unconditionally inside the S3 per-object error loop. Both fields are *string and can be nil (e.g. an error with only Code set). Fix: aws.ToString() for both, which the package already imported.

Regression test: TestFrontendService_EmptyBucket_PerObjectErrorNilFields exercises this with nil Key/Message and confirms no panic.

07-L1 -- Dead Errors field in OrgDiscoveryResult (Low)

internal/accounts/org_discovery.go: OrgDiscoveryResult.Errors []error was declared but never populated and no caller read it. Discovery is all-or-nothing. The dead field implied partial-success semantics that did not exist. Removed.

07-L4 -- Duplicate base64-decode logic in LoginToPublicECR (Low)

internal/deploy/ecr.go: LoginToPublicECR inlined the same base64.StdEncoding.DecodeString + SplitN(":", 2) + parts[1] logic already encapsulated by decodeBase64Token, with a less precise error message. Refactored to call decodeBase64Token and delete the inline copy.

07-N1 -- Docker tag/name passed without validation (Nit)

internal/deploy/docker.go: Added validateDockerRef with ^[A-Za-z0-9][A-Za-z0-9._/:@-]*$. First character must be alphanumeric so leading hyphens (which docker interprets as flags) are rejected. Applied to BuildImage, TagImage, and PushImage.

07-N3 -- IaC templates interpolate user-controlled fields into shell scripts (Nit)

internal/iacfiles/embed.go: Added a security note to the package doc documenting that text/template performs no shell escaping and that the renderer (handler_federation.go) owns validation of user-controlled fields. Added TestCLITemplatesShellMetacharsPassThrough to confirm the pass-through behavior and document the renderer's responsibility.

Verification

go build ./...                                    # Success
go vet ./internal/deploy/... ./internal/accounts/... ./internal/iacfiles/...  # No issues
go test ./internal/deploy/... ./internal/accounts/... ./internal/iacfiles/...  # 115 passed

No live Postgres required; all covered by unit tests with mock clients.

Open questions for reviewer

  • 07-N3: Please confirm that ContactEmail, AccountName, CUDlyAPIURL, and AccountSlug are validated/quoted at the API boundary in handler_federation.go before template.Execute. If not, a follow-up fix is needed there.

…, docker tag validation

Addresses findings 07-M4, 07-L1, 07-L4, 07-N1, 07-N3 from the code review.

- deploy/frontend.go: replace *delErr.Key/*delErr.Message raw dereferences with
  aws.ToString() in EmptyBucket; S3 Error.Key/Message are *string and can be nil
  when only Code is set, causing a panic during bucket teardown (07-M4)
- accounts/org_discovery.go: remove dead Errors []error field from
  OrgDiscoveryResult; discovery is all-or-nothing -- the field was never populated
  and no caller reads it (07-L1)
- deploy/ecr.go: refactor LoginToPublicECR to delegate to decodeBase64Token
  instead of inlining the same decode+split logic; improves error message
  precision (07-L4)
- deploy/docker.go: add validateDockerRef helper with a regexp that requires
  refs to start with an alphanumeric character, rejecting leading hyphens that
  docker would interpret as flags; applied to BuildImage/TagImage/PushImage (07-N1)
- iacfiles/embed.go: add security note documenting that text/template performs no
  shell escaping and that the renderer owns validation of user-controlled fields
  (ContactEmail, AccountName, etc.) before template.Execute (07-N3)

Closes #1057
@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/few Limited audience effort/s Hours type/bug Defect labels Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 11 minutes and 38 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4760dd08-14c5-4d44-b3f6-fad52a20d73f

📥 Commits

Reviewing files that changed from the base of the PR and between cbdc4be and 700be11.

📒 Files selected for processing (9)
  • internal/accounts/org_discovery.go
  • internal/deploy/docker.go
  • internal/deploy/docker_test.go
  • internal/deploy/ecr.go
  • internal/deploy/ecr_test.go
  • internal/deploy/frontend.go
  • internal/deploy/frontend_test.go
  • internal/iacfiles/embed.go
  • internal/iacfiles/templates_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/services-misc-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim

cristim commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
cristim merged commit 45fdc99 into feat/multicloud-web-frontend Jun 7, 2026
4 checks passed
@cristim
cristim deleted the fix/services-misc-cleanup branch July 27, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/few Limited audience priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant