mirror of
https://github.com/Comfy-Org/comfy-swift-sdk.git
synced 2026-11-04 23:47:26 +00:00
[GH-ISSUE #15] Sanitize server-influenced file extension before composing the cache path #1
Labels
No labels
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-swift-sdk#1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mattmillerai on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-swift-sdk/issues/15
Surfaced by CodeRabbit on #10 (the finding is about pre-existing code, so it's tracked here rather than fixed in that comment-only PR).
`Transport` composes the on-disk destination for a downloaded output as:
```swift
.appendingPathComponent("(UUID().uuidString).(suggestedExtension)")
```
`suggestedExtension` is derived from the server's response (content type / filename). If it ever contains `/`, `\`, or `..`, the interpolation can shape the path outside the intended `UUID.ext` filename and write to an unexpected location in the caches directory.
Fix: normalize before use — lowercase, take the last path segment, and constrain to a short alphanumeric whitelist, falling back to `bin`:
```swift
let safe = suggestedExtension.lowercased().split(separator: "/").last.map(String.init) ?? "bin"
let ext = safe.range(of: #"^[a-z0-9]{1,10}$"#, options: .regularExpression) != nil ? safe : "bin"
```
Acceptance: a malicious/garbled extension cannot escape the `UUID().` filename shape; add a unit test with `../`-style and slash-bearing extensions.
@coderabbitai[bot] commented on GitHub (Jun 21, 2026):
🔗 Related PRs
Comfy-Org/ComfySwiftSDK#2 - fix(transport): treat POSIX socket-drop errors as transient so jobs recover via polling [merged]
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!