forked from yencarnacion/html4tree
-
Notifications
You must be signed in to change notification settings - Fork 0
security(ignore): open .html4ignore without following symlinks and contain race failures #594
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
Draft
seonghobae
wants to merge
17
commits into
master
Choose a base branch
from
sentinel-fix-toctou-ignore-file-8644120905595806539
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4ac82b0
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae 28d9943
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae 1db0e9d
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae f61ab7b
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae b372119
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae b9760ec
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae 37fe422
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae ba14d07
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae 6499ee7
fix(ignore): make raced open deterministic and contained
seonghobae 1772fe7
test(ignore): cover deterministic raced-open containment
seonghobae 3f710ec
test(ignore): replace checked entry inside race seam
seonghobae 47182b4
chore: adopt protected-branch CI queue policy before restack
seonghobae 8e9c1fd
chore: non-force restack ignore-file repair onto protected master
seonghobae dd2c45a
🛡️ Sentinel: [HIGH] Fix TOCTOU vulnerability in .html4ignore reading
seonghobae 4798bae
repair(ignore): restore deterministic race contract after stale desce…
seonghobae 32da58c
test(ignore): discard partial policy on read failure
seonghobae e7722b2
fix(ignore): discard partial patterns after read failure
seonghobae 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
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
47 changes: 47 additions & 0 deletions
47
src/test/kotlin/html4tree/IgnoreFilePartialReadFailureTest.kt
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,47 @@ | ||
| package html4tree | ||
|
|
||
| import org.junit.Test | ||
| import java.io.BufferedReader | ||
| import java.io.File | ||
| import java.io.IOException | ||
| import java.io.StringReader | ||
| import java.nio.file.Files | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class IgnoreFilePartialReadFailureTest { | ||
| @Test | ||
| fun partialPatternsAreDiscardedWhenIgnoreReadFails() { | ||
| val tempDir = Files.createTempDirectory("html4tree-ignore-partial-read").toFile() | ||
| try { | ||
| File(tempDir, ".html4ignore").writeText("*.secret\n*.later\n") | ||
| File(tempDir, "leak.secret").writeText("candidate") | ||
| File(tempDir, "keep.txt").writeText("candidate") | ||
| val names = arrayOf(".html4ignore", "leak.secret", "keep.txt") | ||
|
|
||
| val excluded = process_ignore_file(tempDir, names) { | ||
| object : BufferedReader(StringReader("")) { | ||
| private var calls = 0 | ||
|
|
||
| override fun readLine(): String? { | ||
| calls += 1 | ||
| return when (calls) { | ||
| 1 -> "*.secret" | ||
| else -> throw IOException("simulated failure after one parsed policy line") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| assertFalse( | ||
| "leak.secret" in excluded, | ||
| "a failed read must not leave a partially parsed ignore policy active" | ||
| ) | ||
| assertFalse("keep.txt" in excluded) | ||
| assertTrue("index.html" in excluded) | ||
| assertTrue(".html4ignore" in excluded) | ||
| } finally { | ||
| tempDir.deleteRecursively() | ||
| } | ||
| } | ||
| } |
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,63 @@ | ||
| package html4tree | ||
|
|
||
| import org.junit.Test | ||
| import java.io.File | ||
| import java.nio.file.FileSystemException | ||
| import java.nio.file.Files | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class IgnoreFileRaceTest { | ||
| @Test | ||
| fun racedOpenFailureIsContainedAfterPreOpenValidation() { | ||
| val tempDir = Files.createTempDirectory("html4tree-ignore-race").toFile() | ||
| try { | ||
| val ignoreFile = File(tempDir, ".html4ignore") | ||
| ignoreFile.writeText("*.initial\n") | ||
| File(tempDir, "victim.victim").writeText("candidate") | ||
| File(tempDir, "keep.txt").writeText("candidate") | ||
| val names = arrayOf(".html4ignore", "victim.victim", "keep.txt") | ||
| var openerCalled = false | ||
|
|
||
| val excluded = process_ignore_file(tempDir, names) { path -> | ||
| openerCalled = true | ||
| assertEquals(ignoreFile.toPath(), path) | ||
| // The seam is reached only after the regular-file/readability/size | ||
| // checks. Replace that checked directory entry before the open and | ||
| // model the NOFOLLOW open rejecting the raced replacement. | ||
| Files.delete(path) | ||
| Files.writeString(path, "*.victim\n") | ||
| throw FileSystemException(path.toString(), null, "simulated raced replacement") | ||
| } | ||
|
|
||
| assertTrue(openerCalled, "the injected opener must run after pre-open validation") | ||
| assertFalse("victim.victim" in excluded, "raced replacement patterns must not be applied") | ||
| assertFalse("keep.txt" in excluded) | ||
| assertTrue("index.html" in excluded, "mandatory default exclusions must survive the race") | ||
| assertTrue(".html4ignore" in excluded, "the ignore file itself remains excluded") | ||
| } finally { | ||
| tempDir.deleteRecursively() | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun regularIgnoreFileStillAppliesValidPatterns() { | ||
| val tempDir = Files.createTempDirectory("html4tree-ignore-positive").toFile() | ||
| try { | ||
| File(tempDir, ".html4ignore").writeText("*.artifact\n") | ||
| File(tempDir, "plan.artifact").writeText("candidate") | ||
| File(tempDir, "keep.txt").writeText("candidate") | ||
| val names = arrayOf(".html4ignore", "plan.artifact", "keep.txt") | ||
|
|
||
| val excluded = process_ignore_file(tempDir, names) | ||
|
|
||
| assertTrue("plan.artifact" in excluded) | ||
| assertFalse("keep.txt" in excluded) | ||
| assertTrue("index.html" in excluded) | ||
| assertTrue(".html4ignore" in excluded) | ||
| } finally { | ||
| tempDir.deleteRecursively() | ||
| } | ||
| } | ||
| } |
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
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.