Skip to content

fix: harden git credential error handling#1676

Merged
linchao5102 merged 1 commit into
mainfrom
fix/gitcred-credential-safety
Jun 30, 2026
Merged

fix: harden git credential error handling#1676
linchao5102 merged 1 commit into
mainfrom
fix/gitcred-credential-safety

Conversation

@linchao5102

@linchao5102 linchao5102 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Improve the safety of the app Git credential flow by ensuring credential-shaped values from API, keychain, and helper refresh errors are not surfaced in user-visible output.

Changes

  • Add shared redaction for credential-shaped text in Git credential error paths.
  • Redact server-provided Git credential issue errors while preserving typed error metadata, hints, and log IDs.
  • Avoid exposing low-level keychain failure text in public-facing messages while preserving the underlying cause for diagnostics.
  • Document and enforce the Git credential refresh lock ordering to avoid app/URL lock inversion.
  • Add regression coverage for redaction, keychain error wrapping, and refresh failure output.

Test Plan

  • Unit tests pass: make unit-test
  • Manual local verification confirms the lark-cli apps +git-credential-init, +git-credential-list, Git credential helper, and git ls-remote flow works as expected
  • go test -race ./shortcuts/apps/gitcred ./shortcuts/apps -count=1
  • go vet ./shortcuts/apps/gitcred ./shortcuts/apps
  • gofmt -l on changed Go files produced no output
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main

Related Issues

  • None

Summary by CodeRabbit

  • Bug Fixes
    • Git credential error output is now consistently redacted to prevent leaking secrets across credential issuance and refresh flows, including typed error messages and hints (while preserving error causes).
    • Keychain set/remove failures now return fixed, non-leaking messages while keeping the underlying cause.
    • Refresh/lock behavior is safer by enforcing a consistent lock acquisition order.
  • Documentation
    • Clarified the required credential lock acquisition order and lock behavior expectations.
  • Tests
    • Expanded credential redaction tests and nil-handling coverage.
    • Improved Drive e2e cleanup reliability by increasing cleanup timeout and centralizing delete verification with configurable retry logic (including new retry test coverage).

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds credential redaction to git credential errors, wraps keychain failures with structured causes, documents lock ordering, raises cleanup timeout, and centralizes Drive cleanup deletion through a retry-aware helper.

Changes

Credential Error Redaction

Layer / File(s) Summary
Redaction helpers and error wiring
shortcuts/apps/gitcred/helper.go, shortcuts/apps/git_credential.go
Introduces credential-text redaction helpers and routes git credential issuance and manager error output through redacting wrappers.
Keychain error wrapping
shortcuts/apps/gitcred/keychain.go
SecretStore.Set and SecretStore.Remove return structured configuration errors while preserving the underlying keychain cause.
Lock ordering docs
shortcuts/apps/gitcred/lock.go
Package and function comments describe the lockApp and lockURL acquisition order and their blocking behavior.
Credential redaction tests
shortcuts/apps/git_credential_test.go, shortcuts/apps/gitcred/gitcred_test.go
Updates git credential tests to assert redacted messages, preserved causes, and redaction helper behavior.

Drive Cleanup Retry Verification

Layer / File(s) Summary
Cleanup timeout
tests/cli_e2e/core.go
Raises the shared CLI e2e cleanup timeout and updates its comment.
Drive delete retry helper
tests/cli_e2e/drive/helpers.go, tests/cli_e2e/drive/helpers_test.go
Adds retry configuration, JSON payload extraction, and retry classification for Drive delete cleanup commands.
Drive workflow cleanup calls
tests/cli_e2e/drive/drive_add_comment_workflow_test.go, tests/cli_e2e/drive/drive_preview_workflow_test.go, tests/cli_e2e/drive/drive_status_workflow_test.go, tests/cli_e2e/drive/drive_sync_workflow_test.go, tests/cli_e2e/drive/drive_upload_workflow_test.go, tests/cli_e2e/drive/drive_version_workflow_test.go
Switches Drive workflow cleanup paths to DeleteDriveResourceAndVerify across add comment, preview, status, sync, upload, and version tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • liangshuo-1

Poem

🐰 I tucked the secrets in a thicket of hue,
Redacted the crumbs so no one peeks through.
Drive cleanup now hops with a retrying grin,
And tidy little tailwinds whisk clutter back in.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.58% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: hardening Git credential error handling.
Description check ✅ Passed The description matches the template and includes summary, changes, test plan, and related issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/gitcred-credential-safety

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.74%. Comparing base (fb04275) to head (d2e8fe3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/apps/gitcred/helper.go 95.34% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1676      +/-   ##
==========================================
+ Coverage   74.73%   74.74%   +0.01%     
==========================================
  Files         811      811              
  Lines       81965    82011      +46     
==========================================
+ Hits        61258    61302      +44     
- Misses      16138    16139       +1     
- Partials     4569     4570       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@d2e8fe37ff65ca9bd441dda916cb380946f7040e

🧩 Skill update

npx skills add larksuite/cli#fix/gitcred-credential-safety -y -g

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/apps/git_credential_test.go (1)

1062-1083: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the typed classification as well as the redaction.

This test proves the message is scrubbed, but it would still pass if parseIssueCredentialData changed category/subtype on these error paths. Please lock in the expected errs.ProblemOf(err) metadata too, and preserve/capture cause where that branch wraps one. As per coding guidelines **/*_test.go: Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/apps/git_credential_test.go` around lines 1062 - 1083, The test
currently verifies redaction in the error message but does not lock in the typed
error metadata for the `parseIssueCredentialData` error path. Update this
`git_credential_test.go` case to assert the full `errs.ProblemOf(err)`
classification for the returned error, including the expected category, subtype,
and any param values, and also verify cause preservation where that branch wraps
an underlying error. Keep the existing redaction checks, but make the test fail
if `parseIssueCredentialData` changes its typed metadata or drops the wrapped
cause.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/apps/gitcred/gitcred_test.go`:
- Around line 1428-1453: The keychain error-path tests in NewSecretStore.Set and
NewSecretStore.Remove only check the wrapped ConfigError type and cause, so they
can miss a metadata regression. Update these assertions to also verify
errs.ProblemOf(err) for the expected config classification on both branches,
alongside the existing cause-preservation checks, using the Set/Remove failure
paths in gitcred_test.go to locate the test cases.

In `@shortcuts/apps/gitcred/helper.go`:
- Around line 216-223: In the Git credential helper flow, stop unconditionally
wrapping the error returned by lockApp; that code path is downgrading
already-typed errs.InternalError values from the lower layer. Update the error
handling so the app-ID wrapper via errs.NewInternalError is applied only when
lockApp returns an untyped lockfile error, and pass through existing typed
errors unchanged before calling writeCredentialError.

---

Outside diff comments:
In `@shortcuts/apps/git_credential_test.go`:
- Around line 1062-1083: The test currently verifies redaction in the error
message but does not lock in the typed error metadata for the
`parseIssueCredentialData` error path. Update this `git_credential_test.go` case
to assert the full `errs.ProblemOf(err)` classification for the returned error,
including the expected category, subtype, and any param values, and also verify
cause preservation where that branch wraps an underlying error. Keep the
existing redaction checks, but make the test fail if `parseIssueCredentialData`
changes its typed metadata or drops the wrapped cause.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69d7bab9-b543-4c31-b6c5-7aec835ede7a

📥 Commits

Reviewing files that changed from the base of the PR and between 3fcb695 and a991ae8.

📒 Files selected for processing (6)
  • shortcuts/apps/git_credential.go
  • shortcuts/apps/git_credential_test.go
  • shortcuts/apps/gitcred/gitcred_test.go
  • shortcuts/apps/gitcred/helper.go
  • shortcuts/apps/gitcred/keychain.go
  • shortcuts/apps/gitcred/lock.go

Comment thread shortcuts/apps/gitcred/gitcred_test.go Outdated
Comment thread shortcuts/apps/gitcred/helper.go
@linchao5102
linchao5102 force-pushed the fix/gitcred-credential-safety branch from a991ae8 to a73f81f Compare June 30, 2026 09:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/apps/git_credential_test.go (1)

1067-1076: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Also assert the preserved typed metadata (category/subtype), not just Hint.

This is the boundary that redacts a server message while it must "preserve typed error metadata." The test confirms a typed Problem exists and checks Hint, but never asserts the category/subtype, so a classification downgrade during redaction would slip through. Add subtype/category assertions on p to lock the preserved classification.

As per coding guidelines (**/*_test.go): "Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/apps/git_credential_test.go` around lines 1067 - 1076, The test in
gitCredentialError handling currently checks only that errs.ProblemOf returns a
Problem and that Hint/Message are preserved; extend it to assert the preserved
typed metadata on p as well. Add explicit assertions for the category and
subtype fields returned by errs.ProblemOf in this test so redaction cannot
silently downgrade classification, while keeping the existing Hint and message
checks in place.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@shortcuts/apps/git_credential_test.go`:
- Around line 1067-1076: The test in gitCredentialError handling currently
checks only that errs.ProblemOf returns a Problem and that Hint/Message are
preserved; extend it to assert the preserved typed metadata on p as well. Add
explicit assertions for the category and subtype fields returned by
errs.ProblemOf in this test so redaction cannot silently downgrade
classification, while keeping the existing Hint and message checks in place.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a5c0877e-b903-40bf-b878-8ae88ee78b0b

📥 Commits

Reviewing files that changed from the base of the PR and between a991ae8 and a73f81f.

📒 Files selected for processing (6)
  • shortcuts/apps/git_credential.go
  • shortcuts/apps/git_credential_test.go
  • shortcuts/apps/gitcred/gitcred_test.go
  • shortcuts/apps/gitcred/helper.go
  • shortcuts/apps/gitcred/keychain.go
  • shortcuts/apps/gitcred/lock.go
✅ Files skipped from review due to trivial changes (1)
  • shortcuts/apps/gitcred/lock.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • shortcuts/apps/gitcred/keychain.go
  • shortcuts/apps/git_credential.go
  • shortcuts/apps/gitcred/helper.go

@linchao5102
linchao5102 force-pushed the fix/gitcred-credential-safety branch 4 times, most recently from 0cc49f4 to 0a8303b Compare June 30, 2026 10:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/apps/git_credential_test.go`:
- Around line 1090-1096: The leak-check in the git credential test only covers
the formatted password assignment string, so it can miss a raw password leak.
Tighten the assertions around the existing field scan over p.Message and p.Hint
by also checking that the plain samplePassword value itself is absent, alongside
the existing PAT and credential-form checks, so the test catches any regression
where the raw secret appears without the key=value wrapper.

In `@shortcuts/apps/gitcred/gitcred_test.go`:
- Around line 1599-1643: The test setup in
TestManagerGetWrapsUntypedLockAppError is using the default config directory
when calling lockApp(record.AppID), which can fail for unrelated reasons before
the intended ErrHeld path is exercised. Set an isolated config dir at the start
of the test with t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) so lockApp,
NewManager, and Get operate against a clean per-test state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 693f3104-8095-4188-9cf0-e767275096c7

📥 Commits

Reviewing files that changed from the base of the PR and between 25eddbb and 0a8303b.

📒 Files selected for processing (15)
  • shortcuts/apps/git_credential.go
  • shortcuts/apps/git_credential_test.go
  • shortcuts/apps/gitcred/gitcred_test.go
  • shortcuts/apps/gitcred/helper.go
  • shortcuts/apps/gitcred/keychain.go
  • shortcuts/apps/gitcred/lock.go
  • tests/cli_e2e/core.go
  • tests/cli_e2e/drive/drive_add_comment_workflow_test.go
  • tests/cli_e2e/drive/drive_preview_workflow_test.go
  • tests/cli_e2e/drive/drive_status_workflow_test.go
  • tests/cli_e2e/drive/drive_sync_workflow_test.go
  • tests/cli_e2e/drive/drive_upload_workflow_test.go
  • tests/cli_e2e/drive/drive_version_workflow_test.go
  • tests/cli_e2e/drive/helpers.go
  • tests/cli_e2e/drive/helpers_test.go
✅ Files skipped from review due to trivial changes (2)
  • tests/cli_e2e/drive/drive_sync_workflow_test.go
  • shortcuts/apps/gitcred/lock.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • tests/cli_e2e/drive/drive_version_workflow_test.go
  • tests/cli_e2e/drive/drive_upload_workflow_test.go
  • tests/cli_e2e/drive/drive_add_comment_workflow_test.go
  • tests/cli_e2e/core.go
  • shortcuts/apps/gitcred/keychain.go
  • tests/cli_e2e/drive/drive_preview_workflow_test.go
  • tests/cli_e2e/drive/drive_status_workflow_test.go
  • tests/cli_e2e/drive/helpers_test.go
  • shortcuts/apps/git_credential.go
  • tests/cli_e2e/drive/helpers.go
  • shortcuts/apps/gitcred/helper.go

Comment thread shortcuts/apps/git_credential_test.go
Comment thread shortcuts/apps/gitcred/gitcred_test.go Outdated
@linchao5102
linchao5102 force-pushed the fix/gitcred-credential-safety branch 3 times, most recently from a8d1252 to 0cc49f4 Compare June 30, 2026 11:16
@linchao5102
linchao5102 force-pushed the fix/gitcred-credential-safety branch from 0cc49f4 to d2e8fe3 Compare June 30, 2026 11:44
@linchao5102
linchao5102 merged commit 5c4ad52 into main Jun 30, 2026
24 checks passed
@linchao5102
linchao5102 deleted the fix/gitcred-credential-safety branch June 30, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants