Repository navigation
Centralize code/JS sandbox brokers, landlock, bwrap for code #7520
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
Open
Mzack9999
wants to merge
35
commits into
dev
Choose a base branch
from
feat-snd
base: dev
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.
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
3e5f413
harden sandbox
Mzack9999 6414b78
merge dev
Mzack9999 f88573c
harden execution
Mzack9999 5bab1c5
silence staticcheck
Mzack9999 d75f659
drop privileges
Mzack9999 5739365
Merge remote-tracking branch 'origin/dev' into feat-snd
Mzack9999 0881701
portable paths
Mzack9999 895ca21
review fixes
Mzack9999 0f38656
merge origin/dev
Mzack9999 6777d4e
fix grpc
Mzack9999 c36ccf8
merge origin/dev
Mzack9999 596f0eb
fix http
Mzack9999 a55e66b
Merge remote-tracking branch 'origin/dev' into feat-snd
Mzack9999 45ef896
fix tests
Mzack9999 77dc5e7
merge sandbox
Mzack9999 437e7f3
fix lint
Mzack9999 23c9443
fix roots
Mzack9999 c332c6d
state dir
Mzack9999 df8b2bb
own roots
Mzack9999 609e52a
allow refer
Mzack9999 f50c176
browser profile
Mzack9999 52f6850
Merge dev
Mzack9999 ed4fc56
Fix review
Mzack9999 6d68c5e
Deny config
Mzack9999 611104a
Fix docs
Mzack9999 a519603
Merge dev
Mzack9999 44eb73b
Gate landlock
Mzack9999 0f42ab5
Native fallback
Mzack9999 04ed27d
Drop helpers
Mzack9999 f7bd7b7
Scan tempdir
Mzack9999 85c362a
Register infiles
Mzack9999 b63510f
Reuse gozero
Mzack9999 65af13f
Bump gozero
Mzack9999 2f9ec78
Bump gozero
Mzack9999 3066e87
Escape paths
Mzack9999 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
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
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,84 @@ | ||
| //go:build integration | ||
| // +build integration | ||
|
|
||
| package integration_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/projectdiscovery/nuclei/v3/internal/tests/testutils" | ||
| ) | ||
|
|
||
| var securityHardeningTestcases = []integrationCase{ | ||
| {Path: "protocols/javascript/fs-read-deny.yaml", TestCase: &javascriptFSReadDeny{}}, | ||
| {Path: "protocols/javascript/fs-read-deny-lfa.yaml", TestCase: &javascriptFSReadDenyWithLFA{}}, | ||
| {Path: "protocols/javascript/net-deny-excluded.yaml", TestCase: &javascriptNetDenyExcluded{}}, | ||
| {Path: "protocols/javascript/fs-read-allowed-paths.yaml", TestCase: &javascriptFSReadAllowedPaths{}}, | ||
| } | ||
|
|
||
| func securityHardeningRunner(allowLFA bool) *testutils.Runner { | ||
| return suite.runner.Clone(testutils.WithAllowLocalFileAccess(allowLFA)) | ||
| } | ||
|
|
||
| func runSecurityTemplate(filePath string, allowLFA bool, debug bool, extra ...string) ([]string, error) { | ||
| return securityHardeningRunner(allowLFA).TemplateResults(filePath, "127.0.0.1", debug, extra...) | ||
| } | ||
|
|
||
| type javascriptFSReadDeny struct{} | ||
|
|
||
| func (j *javascriptFSReadDeny) Execute(filePath string) error { | ||
| results, err := runSecurityTemplate(filePath, false, debug) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return expectResultsCount(results, 1) | ||
| } | ||
|
|
||
| type javascriptFSReadDenyWithLFA struct{} | ||
|
|
||
| func (j *javascriptFSReadDenyWithLFA) Execute(filePath string) error { | ||
| results, err := runSecurityTemplate(filePath, true, debug, "-allow-local-file-access") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return expectResultsCount(results, 1) | ||
| } | ||
|
|
||
| type javascriptNetDenyExcluded struct{} | ||
|
|
||
| func (j *javascriptNetDenyExcluded) Execute(filePath string) error { | ||
| results, err := runSecurityTemplate(filePath, false, debug, "-eh", "203.0.113.10") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return expectResultsCount(results, 1) | ||
| } | ||
|
|
||
| type javascriptFSReadAllowedPaths struct{} | ||
|
|
||
| func (j *javascriptFSReadAllowedPaths) Execute(filePath string) error { | ||
| grantedDir, err := os.MkdirTemp("", "nuclei-allowed-paths-*") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer os.RemoveAll(grantedDir) | ||
|
|
||
| secretPath := filepath.Join(grantedDir, "secret.txt") | ||
| if err := os.WriteFile(secretPath, []byte("granted-secret"), 0o600); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| results, err := runSecurityTemplate( | ||
| filePath, | ||
| true, | ||
| debug, | ||
| "-allow-local-file-access", | ||
| "-ap", grantedDir, | ||
| "-var", "ReadPath="+secretPath, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return expectResultsCount(results, 1) | ||
| } |
34 changes: 34 additions & 0 deletions
34
internal/tests/integration/testdata/protocols/javascript/fs-read-allowed-paths.yaml
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,34 @@ | ||
| id: javascript-fs-read-allowed-paths | ||
|
|
||
| info: | ||
| name: JavaScript FS Read Allowed Paths | ||
| author: pdteam | ||
| severity: info | ||
| description: reads a file granted via --allowed-paths | ||
|
|
||
| javascript: | ||
| - code: | | ||
| const fs = require('nuclei/fs'); | ||
| let ok = false; | ||
| let content = ""; | ||
| try { | ||
| content = fs.ReadFileAsString(ReadPath); | ||
| ok = content === "granted-secret"; | ||
| } catch (e) { | ||
| ok = false; | ||
| } | ||
| Export(to_json({ ok: ok, content: content })); | ||
| args: | ||
| Host: "{{Host}}" | ||
| ReadPath: "{{ReadPath}}" | ||
| matchers-condition: and | ||
| matchers: | ||
| - type: dsl | ||
| dsl: | ||
| - success == true | ||
| - type: word | ||
| part: response | ||
| condition: and | ||
| words: | ||
| - '"ok": true' | ||
| - "granted-secret" |
33 changes: 33 additions & 0 deletions
33
internal/tests/integration/testdata/protocols/javascript/fs-read-deny-lfa.yaml
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,33 @@ | ||
| id: javascript-fs-read-deny-lfa | ||
|
|
||
| info: | ||
| name: JavaScript FS Read Deny With LFA | ||
| author: pdteam | ||
| severity: info | ||
| description: confirms -lfa does not bypass absolute paths outside the allowlist | ||
|
|
||
| javascript: | ||
| - code: | | ||
| const fs = require('nuclei/fs'); | ||
| let ok = true; | ||
| let errMsg = ""; | ||
| try { | ||
| fs.ReadFileAsString('/etc/passwd'); | ||
| } catch (e) { | ||
| ok = false; | ||
| errMsg = String(e); | ||
| } | ||
| Export(to_json({ ok: ok, err: errMsg })); | ||
| args: | ||
| Host: "{{Host}}" | ||
| matchers-condition: and | ||
| matchers: | ||
| - type: dsl | ||
| dsl: | ||
| - success == true | ||
| - type: word | ||
| part: response | ||
| condition: and | ||
| words: | ||
| - '"ok": false' | ||
| - "outside allowed directories" |
31 changes: 31 additions & 0 deletions
31
internal/tests/integration/testdata/protocols/javascript/fs-read-deny.yaml
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,31 @@ | ||
| id: javascript-fs-read-deny | ||
|
|
||
| info: | ||
| name: JavaScript FS Read Deny | ||
| author: pdteam | ||
| severity: info | ||
| description: attempts to read a file outside the sandbox allowlist | ||
|
|
||
| javascript: | ||
| - code: | | ||
| const fs = require('nuclei/fs'); | ||
| let ok = true; | ||
| let errMsg = ""; | ||
| try { | ||
| fs.ReadFileAsString('/etc/passwd'); | ||
| } catch (e) { | ||
| ok = false; | ||
| errMsg = String(e); | ||
| } | ||
| Export(to_json({ ok: ok, err: errMsg })); | ||
| args: | ||
| Host: "{{Host}}" | ||
| matchers-condition: and | ||
| matchers: | ||
| - type: dsl | ||
| dsl: | ||
| - success == true | ||
| - type: word | ||
| part: response | ||
| words: | ||
| - '"ok": false' |
33 changes: 33 additions & 0 deletions
33
internal/tests/integration/testdata/protocols/javascript/net-deny-excluded.yaml
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,33 @@ | ||
| id: javascript-net-deny-excluded | ||
|
|
||
| info: | ||
| name: JavaScript Net Deny Excluded Host | ||
| author: pdteam | ||
| severity: info | ||
| description: attempts to dial a host blocked by network policy | ||
|
|
||
| javascript: | ||
| - code: | | ||
| const net = require('nuclei/net'); | ||
| let ok = true; | ||
| let errMsg = ""; | ||
| try { | ||
| net.Open('tcp', '203.0.113.10:445'); | ||
| } catch (e) { | ||
| ok = false; | ||
| errMsg = String(e); | ||
| } | ||
| Export(to_json({ ok: ok, err: errMsg })); | ||
| args: | ||
| Host: "{{Host}}" | ||
| matchers-condition: and | ||
| matchers: | ||
| - type: dsl | ||
| dsl: | ||
| - success == true | ||
| - type: word | ||
| part: response | ||
| condition: and | ||
| words: | ||
| - '"ok": false' | ||
| - "denied address found" |
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
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.