Skip to content

fix: address 6 security vulnerabilities - #59

Merged
alexey1312 merged 2 commits into
mainfrom
worktree-security-fixes
Feb 21, 2026
Merged

fix: address 6 security vulnerabilities#59
alexey1312 merged 2 commits into
mainfrom
worktree-security-fixes

Conversation

@alexey1312

Copy link
Copy Markdown
Collaborator

Summary

  • HIGH: Validate download URLs require HTTPS scheme in FileDownloader (SSRF prevention)
  • HIGH: Strip X-Figma-Token and Authorization headers on cross-host redirects via RedirectGuardDelegate
  • MEDIUM: Sandbox PKL evaluator by removing http:/https: from allowed modules and resources
  • MEDIUM: Sanitize Destination.url relative path to prevent ../ directory traversal
  • MEDIUM: Replace try! with throwing makeRequest in UpdateVariablesEndpoint (crash prevention)
  • MEDIUM: Normalize templatesPath via resolvingSymlinksInPath() in all 4 export modules

Test plan

  • All 2174 tests pass
  • SwiftLint strict — no warnings
  • SwiftFormat check — all files clean
  • Verified user config (exfig.pkl with package:// imports) is not affected

🤖 Generated with Claude Code

- HIGH: Validate download URLs require HTTPS scheme (SSRF prevention)
- HIGH: Strip auth headers on cross-host redirects (token leakage)
- MEDIUM: Sandbox PKL evaluator by disabling http/https modules/resources
- MEDIUM: Sanitize Destination path to prevent directory traversal
- MEDIUM: Replace try! with throwing makeRequest in UpdateVariablesEndpoint
- MEDIUM: Normalize templates path via resolvingSymlinksInPath

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

Copy link
Copy Markdown

Summary of Changes

Hello @alexey1312, 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!

This pull request significantly enhances the security posture and stability of the application by addressing six identified vulnerabilities. Key improvements include stricter URL validation for downloads, preventing sensitive header leakage during redirects, sandboxing the PKL evaluator to restrict network access, and fortifying path handling against directory traversal attacks. Additionally, it refines error handling for API requests, contributing to a more robust and secure system.

Highlights

  • SSRF Prevention: Validated download URLs to require HTTPS scheme in FileDownloader.
  • Token Leakage Prevention: Stripped X-Figma-Token and Authorization headers on cross-host redirects via RedirectGuardDelegate.
  • PKL Evaluator Sandboxing: Removed http:/https: from allowed modules and resources for the PKL evaluator.
  • Directory Traversal Prevention: Sanitized Destination.url relative paths to prevent ../ directory traversal.
  • Crash Prevention: Replaced try! with throwing makeRequest in UpdateVariablesEndpoint.
  • Path Normalization: Normalized templatesPath via resolvingSymlinksInPath() in all four export modules.
Changelog
  • Sources/AndroidExport/AndroidExporter.swift
    • Normalized templatesPath by calling resolvingSymlinksInPath().
  • Sources/ExFigCLI/Output/FileDownloader.swift
    • Introduced validateDownloadURL to ensure download URLs use HTTPS and have a valid host.
    • Called validateDownloadURL before initiating file downloads.
  • Sources/ExFigConfig/PKL/PKLEvaluator.swift
    • Defined allowedModules and allowedResources to exclude http: and https: schemes for enhanced sandboxing.
    • Configured PklSwift.withEvaluator to use these restricted options.
  • Sources/ExFigCore/FileContents.swift
    • Added sanitization logic to Destination.url to remove .. and . components from relative paths, preventing directory traversal.
  • Sources/FigmaAPI/Client.swift
    • Introduced RedirectGuardDelegate to handle URLSession redirects.
    • Configured URLSession to use RedirectGuardDelegate for redirect management.
    • Modified request method to try endpoint.makeRequest.
    • Implemented RedirectGuardDelegate to strip X-Figma-Token and Authorization headers on cross-host redirects.
  • Sources/FigmaAPI/Endpoint/Endpoint.swift
    • Changed makeRequest protocol method signature to throws.
  • Sources/FigmaAPI/Endpoint/UpdateVariablesEndpoint.swift
    • Updated makeRequest method signature to throws.
    • Replaced try! with try for JSONCodec.encode(body) to improve error handling.
  • Sources/FlutterExport/FlutterExporter.swift
    • Normalized templatesPath by calling resolvingSymlinksInPath().
  • Sources/WebExport/WebExporter.swift
    • Normalized templatesPath by calling resolvingSymlinksInPath().
  • Sources/XcodeExport/XcodeExporterBase.swift
    • Normalized templatesPath by calling resolvingSymlinksInPath().
  • Tests/ExFigTests/Helpers/MockClient.swift
    • Updated endpoint.makeRequest call to try to align with the new throwing signature.
  • Tests/FigmaAPITests/Mocks/MockClient.swift
    • Updated endpoint.makeRequest call to try to align with the new throwing signature.
  • Tests/FigmaAPITests/UpdateVariablesEndpointTests.swift
    • Updated endpoint.makeRequest calls to try in test assertions to reflect the new throwing signature.
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.

@gemini-code-assist gemini-code-assist 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.

Code Review

The pull request effectively addresses the 6 identified security vulnerabilities. It implements HTTPS enforcement for downloads, strips sensitive headers on cross-host redirects, sandboxes the PKL evaluator, prevents directory traversal in file destinations, improves error handling by removing try!, and normalizes template paths. These changes significantly harden the tool against common attack vectors like SSRF, credential leakage, and path traversal.

Comment thread Sources/FigmaAPI/Client.swift Outdated
- CRITICAL: add HTTPS validation to SharedDownloadQueue batch downloads
- CRITICAL: make RedirectGuardDelegate fail-closed on nil hosts
- HIGH: strip headers on HTTPS→HTTP scheme downgrade in redirects
- HIGH: add @unchecked Sendable and internal access to RedirectGuardDelegate
- HIGH: fix orphaned doc comment in PKLEvaluator
- HIGH: replace fatalError with throw in 3 endpoint makeRequest methods
- MEDIUM: guard against empty path after sanitization in Destination.url
- MEDIUM: add 13 security tests (path traversal, redirect guard, endpoints)
@alexey1312
alexey1312 merged commit 56ad2b1 into main Feb 21, 2026
3 checks passed
@alexey1312
alexey1312 deleted the worktree-security-fixes branch February 21, 2026 18:28
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.

1 participant