returning 'nil' for non-existing origin as opposed to an empty string (#4135)

* returning 'nil' for non-existing origin as opposed to an empty string

* version bump
This commit is contained in:
Jędrzej Stuczyński
2023-11-14 11:16:16 +00:00
committed by GitHub
parent f9a4ca5a22
commit f1a5a0ccd7
28 changed files with 69 additions and 54 deletions
Generated
+4 -4
View File
@@ -2994,7 +2994,7 @@ dependencies = [
[[package]]
name = "extension-storage"
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
dependencies = [
"bip39",
"console_error_panic_hook",
@@ -5568,7 +5568,7 @@ dependencies = [
[[package]]
name = "mix-fetch-wasm"
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
dependencies = [
"async-trait",
"futures",
@@ -6270,7 +6270,7 @@ dependencies = [
[[package]]
name = "nym-client-wasm"
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
dependencies = [
"anyhow",
"futures",
@@ -6972,7 +6972,7 @@ dependencies = [
[[package]]
name = "nym-node-tester-wasm"
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
dependencies = [
"futures",
"js-sys",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "extension-storage"
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/nymtech/nym"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@nymproject/nym-wallet-app",
"version": "1.2.12-rc.1",
"version": "1.2.12-rc.2",
"license": "MIT",
"main": "index.js",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/contract-clients",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"description": "A client for all Nym smart contracts",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@nymproject/ts-sdk-docs",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"description": "Nym Typescript SDK Docs",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
@@ -28,9 +28,9 @@
"@mui/icons-material": "^5.14.9",
"@mui/lab": "^5.0.0-alpha.145",
"@mui/material": "^5.14.8",
"@nymproject/contract-clients": ">=1.2.4-rc.1 || ^1",
"@nymproject/mix-fetch-full-fat": ">=1.2.4-rc.1 || ^1",
"@nymproject/sdk-full-fat": ">=1.2.4-rc.1 || ^1",
"@nymproject/contract-clients": ">=1.2.4-rc.2 || ^1",
"@nymproject/mix-fetch-full-fat": ">=1.2.4-rc.2 || ^1",
"@nymproject/sdk-full-fat": ">=1.2.4-rc.2 || ^1",
"chain-registry": "^1.19.0",
"cosmjs-types": "^0.8.0",
"next": "^13.4.19",
@@ -50,4 +50,4 @@
"typescript": "^4.9.3"
},
"private": false
}
}
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-plain-html-parcel",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "An example project that uses WASM and plain HTML bundled with Parcel v2",
"license": "Apache-2.0",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-plain-html",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "An example project that uses WASM and plain HTML",
"license": "Apache-2.0",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-react-webpack-wasm",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "An example project that uses WASM, React, Webpack, Typescript and the Nym theme + components library",
"license": "Apache-2.0",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-chrome-extension",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "This is an example of how Nym can be used within the context of a Chrome extension.",
"license": "ISC",
"author": "",
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-firefox-extension",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "This is an example of how Nym can be used within the context of a Firefox extension.",
"license": "ISC",
"author": "",
@@ -1,6 +1,6 @@
{
"name": "@nymproject/mix-fetch-example-parcel",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"license": "Apache-2.0",
"scripts": {
"build": "parcel build --no-cache --no-content-hash",
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-node-tester-plain-html-parcel",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "An example project that uses WASM and plain HTML bundled with Parcel v2",
"license": "Apache-2.0",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-node-tester-plain-html",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "An example project that uses WASM node tester and plain HTML",
"license": "Apache-2.0",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-example-node-tester-react",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"description": "An example project that uses WASM node tester and React",
"license": "Apache-2.0",
"scripts": {
@@ -1,6 +1,6 @@
{
"name": "@nymproject/mix-fetch-node",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"description": "This package is a drop-in replacement for `fetch` in NodeJS to send HTTP requests over the Nym Mixnet.",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
@@ -28,7 +28,7 @@
"tsc": "tsc --noEmit true"
},
"dependencies": {
"@nymproject/mix-fetch-wasm-node": ">=1.2.4-rc.1 || ^1",
"@nymproject/mix-fetch-wasm-node": ">=1.2.4-rc.2 || ^1",
"comlink": "^4.3.1",
"fake-indexeddb": "^5.0.0",
"node-fetch": "^3.3.2",
@@ -68,4 +68,4 @@
},
"private": false,
"types": "./dist/cjs/index.d.ts"
}
}
@@ -1,6 +1,6 @@
{
"name": "@nymproject/mix-fetch-tester-webpack",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"license": "Apache-2.0",
"scripts": {
"build": "webpack build --progress --config webpack.prod.js",
@@ -1,6 +1,6 @@
{
"name": "@nymproject/mix-fetch-tester-parcel",
"version": "1.0.4-rc.1",
"version": "1.0.4-rc.2",
"license": "Apache-2.0",
"scripts": {
"build": "npx parcel build --no-cache --no-content-hash",
@@ -1,6 +1,6 @@
{
"name": "@nymproject/mix-fetch",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"description": "This package is a drop-in replacement for `fetch` to send HTTP requests over the Nym Mixnet.",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
@@ -34,7 +34,7 @@
"tsc": "tsc --noEmit true"
},
"dependencies": {
"@nymproject/mix-fetch-wasm": ">=1.2.4-rc.1 || ^1",
"@nymproject/mix-fetch-wasm": ">=1.2.4-rc.2 || ^1",
"comlink": "^4.3.1"
},
"devDependencies": {
@@ -82,4 +82,4 @@
"private": false,
"type": "module",
"types": "./dist/esm/index.d.ts"
}
}
@@ -1,6 +1,6 @@
{
"name": "@nymproject/node-tester",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"description": "This package provides a tester that can send test packets to mixnode that is part of the Nym Mixnet.",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
@@ -25,7 +25,7 @@
"tsc": "tsc --noEmit true"
},
"dependencies": {
"@nymproject/nym-node-tester-wasm": ">=1.2.4-rc.1 || ^1",
"@nymproject/nym-node-tester-wasm": ">=1.2.4-rc.2 || ^1",
"comlink": "^4.3.1"
},
"devDependencies": {
@@ -71,4 +71,4 @@
"private": false,
"type": "module",
"types": "./dist/esm/index.d.ts"
}
}
@@ -1,6 +1,6 @@
{
"name": "@nymproject/nodejs-client",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
"files": [
@@ -25,7 +25,7 @@
"tsc": "tsc --noEmit true"
},
"dependencies": {
"@nymproject/nym-client-wasm-node": ">=1.2.4-rc.1 || ^1",
"@nymproject/nym-client-wasm-node": ">=1.2.4-rc.2 || ^1",
"comlink": "^4.3.1",
"fake-indexeddb": "^4.0.2",
"rollup-plugin-polyfill": "^4.2.0",
@@ -66,4 +66,4 @@
},
"private": false,
"types": "./dist/index.d.ts"
}
}
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk-react",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
"files": [
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@nymproject/sdk",
"version": "1.2.4-rc.1",
"version": "1.2.4-rc.2",
"license": "Apache-2.0",
"author": "Nym Technologies SA",
"files": [
@@ -31,7 +31,7 @@
"tsc": "tsc --noEmit true"
},
"dependencies": {
"@nymproject/nym-client-wasm": ">=1.2.4-rc.1 || ^1",
"@nymproject/nym-client-wasm": ">=1.2.4-rc.2 || ^1",
"comlink": "^4.3.1"
},
"devDependencies": {
@@ -81,4 +81,4 @@
"private": false,
"type": "module",
"types": "./dist/esm/index.d.ts"
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "nym-client-wasm"
authors = ["Dave Hrycyszyn <futurechimp@users.noreply.github.com>", "Jedrzej Stuczynski <andrew@nymtech.net>"]
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
edition = "2021"
keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"]
license = "Apache-2.0"
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "mix-fetch-wasm"
authors = ["Jedrzej Stuczynski <andrew@nymtech.net>"]
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
edition = "2021"
keywords = ["nym", "fetch", "wasm", "webassembly", "privacy"]
license = "Apache-2.0"
@@ -195,7 +195,7 @@ func parseHeaders(headers js.Value, reqOpts types.RequestOptions, method string)
// 3.1.1
origin := jstypes.Origin()
serializedOrigin := &origin
serializedOrigin := origin
// Reference: https://fetch.spec.whatwg.org/#origin-header
// TODO: 3.1.2: check response tainting
// 3.1.3
@@ -224,7 +224,7 @@ func parseBody(request *js.Value) (io.Reader, error) {
jsBody := request.Get(fieldRequestBody)
var bodyReader io.Reader
if jsBody.InstanceOf(js.Global().Get("ReadableStream")) && jsBody.Get("getReader").Type() == js.TypeFunction {
if jsBody.InstanceOf(js.Global().Get("ReadableStream")) && jsBody.Get("getReader").Type() == js.TypeFunction {
// Check to see if getReader is a function
log.Debug("stream body - getReader")
bodyReader = external.NewStreamReader(jsBody.Call("getReader"))
@@ -20,20 +20,26 @@ var (
Headers = js.Global().Get("Headers")
)
func Origin() string {
func Origin() *string {
// nodejs doesn't have origin
location := js.Global().Get("location")
if !location.IsUndefined() && !location.IsNull() {
return location.Get("origin").String()
origin := location.Get("origin").String()
return &origin
} else {
return ""
return nil
}
}
func OriginUrl() *url.URL {
originUrl, originErr := url.Parse(Origin())
if originErr != nil {
panic(fmt.Sprintf("could not obtain origin: %s", originErr))
origin := Origin()
if origin == nil {
return nil
} else {
originUrl, originErr := url.Parse(*origin)
if originErr != nil {
panic(fmt.Sprintf("could not obtain origin: %s", originErr))
}
return originUrl
}
return originUrl
}
@@ -92,7 +92,7 @@ func mainFetchChecks(req *conv.ParsedRequest) error {
return nil
}
if req.Options.Mode == jstypes.ModeSameOrigin {
return errors.New(fmt.Sprintf("MixFetch API cannot load %s. Request mode is \"%s\" but the URL's origin is not same as the request origin %s.", req.Request.URL.String(), jstypes.ModeSameOrigin, jstypes.Origin))
return errors.New(fmt.Sprintf("MixFetch API cannot load %s. Request mode is \"%s\" but the URL's origin is not same as the request origin %v.", req.Request.URL.String(), jstypes.ModeSameOrigin, jstypes.Origin()))
}
if req.Options.Mode == jstypes.ModeNoCors {
if req.Options.Redirect != jstypes.RequestRedirectFollow {
@@ -241,8 +241,17 @@ func doCorsCheck(reqOpts *types.RequestOptions, resp *http.Response) error {
// 4.9.4
// TODO: presumably this needs to better account for the wildcard?
if jstypes.Origin() != originHeader {
return errors.New(fmt.Sprintf("\"%s\" does not match the origin \"%s\" on \"%s\" remote header", jstypes.Origin, originHeader, jstypes.HeaderAllowOrigin))
// if origin is null it means 4.9.2 would have failed anyway
origin := jstypes.Origin()
if origin == nil {
// TODO: won't this essentially fail all node requests?
return errors.New("the local origin is null")
}
// safety: it's fine to dereference the pointer here as we've just checked if it's null
if *origin != originHeader {
return errors.New(fmt.Sprintf("\"%v\" does not match the origin \"%s\" on \"%s\" remote header", jstypes.Origin(), originHeader, jstypes.HeaderAllowOrigin))
}
// 4.9.5
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "nym-node-tester-wasm"
authors = ["Jedrzej Stuczynski <andrew@nymtech.net>"]
version = "1.2.4-rc.1"
version = "1.2.4-rc.2"
edition = "2021"
keywords = ["nym", "sphinx", "webassembly", "privacy", "tester"]
license = "Apache-2.0"