Skip to content

fix: parse hex-encoded macOS Keychain credentials#38

Merged
say8425 merged 2 commits intomainfrom
fix/37-hex-keychain-credentials
Feb 27, 2026
Merged

fix: parse hex-encoded macOS Keychain credentials#38
say8425 merged 2 commits intomainfrom
fix/37-hex-keychain-credentials

Conversation

@say8425
Copy link
Owner

@say8425 say8425 commented Feb 27, 2026

Summary

  • macOS security find-generic-password -w가 non-printable 문자(\x07 prefix) 포함 시 hex 문자열로 출력하여 JSON.parse() 실패 → --show-usage usage 줄 미표시
  • parseCredentialString() 순수 함수 추출: hex 감지 → 디코딩 → JSON 파싱, binary prefix 시 brace-matching fallback
  • 9개 테스트 케이스 추가 (token.test.ts)

Closes #37

Test plan

  • bun test 전체 106개 통과
  • 수동 테스트: --show-usage 시 3번째 줄(⏳/📊/⏰/📅) 정상 표시 확인

🤖 Generated with Claude Code

macOS `security find-generic-password -w` outputs hex strings when
credentials contain non-printable characters (\x07 prefix). Extract
parseCredentialString() as a pure function that detects hex encoding,
decodes it, and falls back to brace-matching for binary-prefixed JSON.

Closes #37

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 Pull Request는 macOS Keychain에서 자격 증명을 읽을 때 발생하는 파싱 오류를 해결합니다. 기존에는 Keychain이 비인쇄 문자를 포함하는 암호를 헥스 인코딩된 문자열로 반환하여 JSON.parse()가 실패하는 문제가 있었습니다. 이를 해결하기 위해, 헥스 인코딩된 문자열과 바이너리 접두사가 붙은 JSON 형식을 모두 처리할 수 있는 새로운 parseCredentialString 함수를 도입하여, accessToken을 안정적으로 추출할 수 있도록 개선했습니다. 이 변경으로 macOS 환경에서 자격 증명 검색의 신뢰성이 향상됩니다.

Highlights

  • macOS Keychain credential parsing: macOS security find-generic-password -w 명령어가 non-printable 문자를 포함하는 경우 hex 문자열로 출력되어 JSON.parse() 실패하던 문제를 해결했습니다.
  • Credential parsing logic refactoring: parseCredentialString() 순수 함수를 추출하여 hex 감지, 디코딩, JSON 파싱 로직을 통합하고, binary prefix가 있는 경우 brace-matching fallback을 추가했습니다.
  • Test coverage: token.test.ts에 9개의 새로운 테스트 케이스를 추가하여 다양한 시나리오에서 credential 파싱의 견고성을 확보했습니다.
Changelog
  • src/tests/token.test.ts
    • 새로운 테스트 파일을 추가했습니다.
    • 유효한 JSON, 헥스 인코딩된 JSON, 바이너리 접두사가 붙은 헥스 문자열 등 다양한 시나리오에 대한 테스트 케이스를 포함했습니다.
    • 비어 있거나 공백만 있는 문자열, 유효하지 않은 입력, claudeAiOauth 키 또는 accessToken 필드가 없는 경우에 대한 테스트를 추가했습니다.
  • src/usage/token.ts
    • credential 문자열에서 accessToken을 추출하는 parseCredentialString 순수 함수를 새로 정의했습니다.
    • 입력 문자열이 헥스 인코딩된 경우 이를 디코딩하는 로직을 추가했습니다.
    • 표준 JSON 파싱이 실패할 경우, 바이너리 접두사가 붙은 문자열에서 brace-matching을 통해 내부 JSON을 추출하는 fallback 로직을 구현했습니다.
    • getAccessToken 함수가 새로 정의된 parseCredentialString 함수를 사용하도록 업데이트했습니다.
Activity
  • PR은 이슈 #37을 해결합니다.
  • 작성자는 bun test의 106개 테스트가 모두 통과했음을 확인했습니다.
  • 작성자는 --show-usage 시 3번째 줄(⏳/📊/⏰/📅)이 정상 표시되는지 수동 테스트를 완료했습니다.
  • 이 PR은 Claude Code를 사용하여 생성되었습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 macOS Keychain에서 non-printable 문자가 포함된 credential을 읽어올 때 security 명령어가 16진수 문자열을 반환하여 발생하는 파싱 오류를 해결합니다. parseCredentialString이라는 순수 함수를 도입하여 16진수 감지 및 디코딩, 그리고 바이너리 접두사가 붙은 경우에 대한 처리를 포함한 파싱 로직을 캡슐화한 점이 좋습니다. 또한, 추가된 9개의 테스트 케이스는 새로운 함수의 동작을 다양한 엣지 케이스에 대해 검증하여 코드의 안정성을 높여줍니다. 전반적으로 훌륭한 수정이지만, 16진수 문자열을 감지하는 로직을 조금 더 견고하게 만들면 더 좋을 것 같습니다. 자세한 내용은 아래 주석을 참고해주세요.

Prevents false positives where short hex-like strings (e.g. "face")
would be incorrectly decoded as hex-encoded credentials.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@say8425 say8425 self-assigned this Feb 27, 2026
@say8425 say8425 merged commit 7e0815c into main Feb 27, 2026
2 checks passed
@say8425 say8425 deleted the fix/37-hex-keychain-credentials branch February 27, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: --show-usage not working due to hex-encoded Keychain credentials

1 participant