Repository navigation
feat: Deeplinks hardenning #1988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b09f851
chore(deps): Require ios-core 19.1.3
adrien-coye a9ea2b9
feat(security): Harden shared file imports
adrien-coye d9d976a
test(security): Cover shared file import boundaries
adrien-coye 5f5aeae
refactor(security): Simplify shared file hardening
adrien-coye d0072fe
refactor(security): Share file handoff contract
adrien-coye 351a6b2
refactor: Inject shared container URL
adrien-coye 88f57b9
fix: Update shared file handoff symbols
adrien-coye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
120 changes: 120 additions & 0 deletions
120
kDriveTests/kDriveCore/DeepLinks/UTFileSharingDeeplink.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| Infomaniak kDrive - iOS App | ||
| Copyright (C) 2026 Infomaniak Network SA | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| import Foundation | ||
| import InfomaniakCore | ||
| @testable import kDriveCore | ||
| import XCTest | ||
|
|
||
| final class UTFileSharingDeeplink: XCTestCase { | ||
| private let fileManager = FileManager.default | ||
| private var testRootURL: URL! | ||
| private var sharedContainerURL: URL! | ||
| private var handoffRootURL: URL! | ||
|
|
||
| override func setUpWithError() throws { | ||
| try super.setUpWithError() | ||
| testRootURL = fileManager.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) | ||
| sharedContainerURL = testRootURL.appendingPathComponent("shared", isDirectory: true) | ||
| handoffRootURL = KDriveFileSharingConstants.handoffDirectoryURL(in: sharedContainerURL) | ||
| try fileManager.createDirectory(at: handoffRootURL, withIntermediateDirectories: true) | ||
| } | ||
|
|
||
| override func tearDownWithError() throws { | ||
| try? fileManager.removeItem(at: testRootURL) | ||
| try super.tearDownWithError() | ||
| } | ||
|
|
||
| func testAcceptsRegularFileFromHandoffDirectory() throws { | ||
| let sourceURL = try createSourceFile() | ||
|
|
||
| let deeplinkURL = try makeURL(for: sourceURL) | ||
| let files = DeeplinkParser(sharedContainerURL: sharedContainerURL).filesForSharingDeeplink(deeplinkURL) | ||
|
|
||
| XCTAssertEqual(files?.count, 1) | ||
| XCTAssertEqual(files?.first?.name, sourceURL.lastPathComponent) | ||
| XCTAssertEqual(files?.first?.path, sourceURL) | ||
| } | ||
|
|
||
| func testRejectsWrongRoute() throws { | ||
| let sourceURL = try createSourceFile() | ||
| let parser = DeeplinkParser(sharedContainerURL: sharedContainerURL) | ||
|
|
||
| let wrongSchemeURL = try makeURL(for: sourceURL, scheme: "kdrive") | ||
| let wrongHostURL = try makeURL(for: sourceURL, host: "other") | ||
|
|
||
| XCTAssertNil(parser.filesForSharingDeeplink(wrongSchemeURL)) | ||
| XCTAssertNil(parser.filesForSharingDeeplink(wrongHostURL)) | ||
| } | ||
|
|
||
| func testRejectsFileOutsideHandoffDirectory() throws { | ||
| let outsideURL = testRootURL.appendingPathComponent("outside.txt") | ||
| try Data().write(to: outsideURL) | ||
|
|
||
| let deeplinkURL = try makeURL(for: outsideURL) | ||
| let files = DeeplinkParser(sharedContainerURL: sharedContainerURL).filesForSharingDeeplink(deeplinkURL) | ||
|
|
||
| XCTAssertNil(files) | ||
| } | ||
|
|
||
| func testRejectsSymlinkEscapingHandoffDirectory() throws { | ||
| let outsideURL = testRootURL.appendingPathComponent("outside.txt") | ||
| try Data().write(to: outsideURL) | ||
| let symlinkURL = try createHandoffDirectory().appendingPathComponent("link.txt") | ||
| try fileManager.createSymbolicLink(at: symlinkURL, withDestinationURL: outsideURL) | ||
|
|
||
| let deeplinkURL = try makeURL(for: symlinkURL) | ||
| let files = DeeplinkParser(sharedContainerURL: sharedContainerURL).filesForSharingDeeplink(deeplinkURL) | ||
|
|
||
| XCTAssertNil(files) | ||
| } | ||
|
|
||
| func testRejectsDirectory() throws { | ||
| let directoryURL = try createHandoffDirectory().appendingPathComponent("folder", isDirectory: true) | ||
| try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: false) | ||
|
|
||
| let deeplinkURL = try makeURL(for: directoryURL) | ||
| let files = DeeplinkParser(sharedContainerURL: sharedContainerURL).filesForSharingDeeplink(deeplinkURL) | ||
|
|
||
| XCTAssertNil(files) | ||
| } | ||
|
|
||
| private func createHandoffDirectory() throws -> URL { | ||
| let directoryURL = handoffRootURL.appendingPathComponent(UUID().uuidString, isDirectory: true) | ||
| try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: false) | ||
| return directoryURL | ||
| } | ||
|
|
||
| private func createSourceFile() throws -> URL { | ||
| let sourceURL = try createHandoffDirectory().appendingPathComponent("file.txt") | ||
| try Data("content".utf8).write(to: sourceURL) | ||
| return sourceURL | ||
| } | ||
|
|
||
| private func makeURL( | ||
| for sourceURL: URL, | ||
| scheme: String = KDriveFileSharingConstants.scheme, | ||
| host: String = KDriveFileSharingConstants.host | ||
| ) throws -> URL { | ||
| var components = URLComponents() | ||
| components.scheme = scheme | ||
| components.host = host | ||
| components.queryItems = [URLQueryItem(name: KDriveFileSharingConstants.urlQueryItemName, value: sourceURL.path)] | ||
| return try XCTUnwrap(components.url) | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.