MCPcopy Create free account
hub / github.com/tailscale/tailscale / TestSecretTokenAuth

Function TestSecretTokenAuth

drive/driveimpl/drive_test.go:205–228  ·  view source on GitHub ↗

TestSecretTokenAuth verifies that the fileserver running at localhost cannot be accessed directly without the correct secret token. This matters because if a victim can be induced to visit the localhost URL and access a malicious file on their own share, it could allow a Mark-of-the-Web bypass attac

(t *testing.T)

Source from the content-addressed store, hash-verified

203// if a victim can be induced to visit the localhost URL and access a malicious
204// file on their own share, it could allow a Mark-of-the-Web bypass attack.
205func TestSecretTokenAuth(t *testing.T) {
206 s := newSystem(t)
207
208 fileserverAddr := s.addRemote(remote1)
209 s.addShare(remote1, share11, drive.PermissionReadWrite)
210 s.writeFile("writing file to read/write remote should succeed", remote1, share11, file111, "hello world", true)
211
212 client := &http.Client{
213 Transport: &http.Transport{DisableKeepAlives: true},
214 }
215 addr := strings.Split(fileserverAddr, "|")[1]
216 wrongSecret, err := generateSecretToken()
217 if err != nil {
218 t.Fatal(err)
219 }
220 u := fmt.Sprintf("http://%s/%s/%s", addr, wrongSecret, url.PathEscape(file111))
221 resp, err := client.Get(u)
222 if err != nil {
223 t.Fatal(err)
224 }
225 if resp.StatusCode != http.StatusForbidden {
226 t.Errorf("expected %d for incorrect secret token, but got %d", http.StatusForbidden, resp.StatusCode)
227 }
228}
229
230func TestLOCK(t *testing.T) {
231 s := newSystem(t)

Callers

nothing calls this directly

Calls 9

newSystemFunction · 0.85
generateSecretTokenFunction · 0.85
addRemoteMethod · 0.80
addShareMethod · 0.80
writeFileMethod · 0.80
SplitMethod · 0.80
FatalMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…