Skip to content

Commit c48b612

Browse files
fix: add companion ids to allow origins
- fixes #8689 - Adds the chrome-extension ids for ipfs-companion and ipfs-companion-beta to the allowed origins list, this allows us to accesss ipfs api from a manifest v3 extension. - added tests in t0401-api-browser-security.sh
1 parent 5e1b224 commit c48b612

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/corehttp/commands.go

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ var defaultLocalhostOrigins = []string{
4444
"https://[::1]:<port>",
4545
"http://localhost:<port>",
4646
"https://localhost:<port>",
47+
"chrome-extension://nibjojkomfdiaoajekhjakgkdhaomnch", // ipfs-companion
48+
"chrome-extension://hjoieblefckbooibpepigmacodalfndh", // ipfs-companion-beta
4749
}
4850

4951
func addCORSFromEnv(c *cmdsHttp.ServerConfig) {

test/sharness/t0401-api-browser-security.sh

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ test_expect_success "browser is able to access API if Origin is the API port on
3939
grep "HTTP/1.1 200 OK" curl_output && grep "$PEERID" curl_output
4040
'
4141

42+
test_expect_success "Companion extension is unable to access API with invalid Origin" '
43+
curl -sD - -X POST -A "Mozilla" -H "Origin: chrome-extension://invalidextensionid" "http://127.0.0.1:$API_PORT/api/v0/id" >curl_output &&
44+
grep "HTTP/1.1 403 Forbidden" curl_output
45+
'
46+
47+
test_expect_success "Companion extension is able to access API if Origin is the API port on localhost (ipv4)" '
48+
curl -sD - -X POST -A "Mozilla" -H "Origin: chrome-extension://nibjojkomfdiaoajekhjakgkdhaomnch" "http://127.0.0.1:$API_PORT/api/v0/id" >curl_output &&
49+
grep "HTTP/1.1 200 OK" curl_output && grep "$PEERID" curl_output
50+
'
51+
52+
test_expect_success "Companion beta extension is able to access API if Origin is the API port on localhost (ipv4)" '
53+
curl -sD - -X POST -A "Mozilla" -H "Origin: chrome-extension://hjoieblefckbooibpepigmacodalfndh" "http://127.0.0.1:$API_PORT/api/v0/id" >curl_output &&
54+
grep "HTTP/1.1 200 OK" curl_output && grep "$PEERID" curl_output
55+
'
56+
4257
test_kill_ipfs_daemon
4358

4459
test_expect_success "setting CORS in API.HTTPHeaders works via CLI" "

0 commit comments

Comments
 (0)