Repository navigation
fix(security): delete dead code and harden MIME, attachment paths, OAuth, and token storage - #19
Merged
Merged
Conversation
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
Removes dead code and hardens outbound MIME construction, inbound attachment downloads, local OAuth callbacks, and account/token persistence.
Changes
Dead code removal
GmailService.updateDraft()(src/gmail-service.ts).accessToken?: stringfromEmailAccount.oauth2(src/types.ts) and itssetCredentialsreference..mailcp/entry from.gitignore.Deduplicated & hardened MIME builder (
src/gmail-service.ts)buildRawMimeMessage(...)andvalidateAttachmentPaths(...)shared bycreateDraftandsendMessage.From,To,Cc,Bcc,Subject,In-Reply-To,References, and attachment filenames.encodeMimeHeaderUTF-8 Base64 encoded-words to<= 75chars per token on clean UTF-8 code-point boundaries (no split multi-byte characters or emoji).Content-Transfer-Encoding: base64with 76-char\r\nwrapping for UTF-8 text/HTML bodies and attachment payloads.Content-Dispositionattachment filenames (strip CR/LF/NUL//, escape\and") and switched MIME boundaries tocrypto.randomBytes(16).toString("hex").--attachpaths (exists, regular file, total bytes<= 25 MB) before making Gmail API calls.Inbound attachment path traversal fix & deduplication (
src/gmail-service.ts)downloadPartsForMessages(...)used by bothgetThread(..., true)anddownloadMessageAttachments(...).\→/,path.posix.basename, strip control chars & leading dots, fallback to"attachment") and enforcedpath.resolve(filePath).startsWith(path.resolve(attachmentDir) + path.sep).0700permissions on the attachments directory (including pre-existing directories) and0600on downloaded files.Hardened account & token storage (
src/account-storage.ts)0700on the config directory (new and existing).accounts.jsonandcredentials.jsonsaves to atomic same-directory temp-file writes (0600+chmodSync+renameSync).ENOENT; invalid JSON, non-array payloads, or read errors now throw an actionable error instead of silently returning[].Hardened OAuth flow (
src/gmail-oauth-flow.ts)state(crypto.randomBytes(24).toString("hex")) andprompt: "consent", strictly verified withcrypto.timingSafeEqualbefore token exchange.escapeHtml) in localhost callback error responses to prevent reflected HTML injection.url.parse()withnew URL(...)and removed access to privateoauth2Client._clientId/_clientSecret.Verification
npm ci --no-audit --no-fundnpm run buildnode --test test/*.test.js— 39/39 passing (including newtest/security-mime-storage.test.js)npx biome check src/— clean (7 files checked)npx tsc --noEmit— clean