-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Internal Origin for Persistence #11882
Comments
This is very arbitrary IMO. It would be a lot simpler if root specifiers were always given unique opaque origins and users had to pass a
|
Upon reflection, I agree. I think we should just drop the shared implicit location for the parent root. It would simply be: The internal origin will be determined in the following way:
|
) Closes #11882 BREAKING CHANGE: Previously when `--location` was set, the unique storage key was derived from the the URL of the location instead of just the origin. This change correctly uses just the origin. This may cause previously persisted storage to change its key and data to not be available with the same location as before.
Context
Currently, in order to enabled
localStorage
a--location
must be supplied on the command line, so that the origin of the--location
can be used to "scope" the local storage.We plan to add more persistence to Deno, like
CacheStorage
andIndexedDB
and all web standard persistence revolves around the concept of "scoping" the persisted data to an origin.A lack of an implicit origin provides lots of usability challenges, as while setting the
--location
is desirable for specific use cases, the average user just wants to run some workloads that persist data in a predictable and secure way. Especially when using other code written for the web platform, they just want to grab the code and have it work.For additional context there are a few definitions important to this discussion...
What is an origin?
Origin is an HTML concept that is the foundation for security for the web platform APIs. It is used to determine if some code is from the same "place" as other code to help determine how to deal with it securely. In addition it can also be used to determine what persisted data is visible to a given script.
There are two types of origins defined in the HTML specification:
null
" per serialization of an origin), for which the only meaningful operation is testing for equality.In the URL specification, origin sits outside of other properties and how its own serialization algorithm outside of the URL specification.
What is an opaque origin?
The definition in the specification is:
The author thinks it is important to note that specification says that there is no serialization an opaque origin can be "recreated" from and should always be serialized as null. It is important to note though that one opaque origin
can be compared to another, so opaque origins are not intended to always be unique, that given some internal algorithm, you can arrive at an opaque origin that is equal to another opaque origin.
In fact, there are explicit algorithm which indicate opaque origins are intended to be comparable:
It simply implies that an opaque origin cannot be set by using a serialized origin. What you get when you deserialize an origin is always a tuple origin (if valid).
What is the origin of specific URL schemes?
The algorithm for determining the origin for a URL is
specified as:
"blob"
schemes use blob URL entries environment origin, or a url parsing of the URL's path[0], otherwise a new opaque origin."ftp"
,"http"
,"https"
,"ws"
,"wss"
schemes return a tuple origin."file"
schemes have undefined behavior, but suggest that a new opaque origin should be used.Solution
Internal Origin
The Deno CLI will have the concept of internal origin which will be determined at startup and be immutable for the lifetime of main worker. The internal origin will be used by processes that need to determine the origin to associate with some function, like persisting data (e.g. the origin to associate with data from
localStorage
).The internal origin will be determined in the following way:
--location
flag was set at startup, the internal origin will be the origin of a URL parse of the supplied argument. It is assumed that if the URL parse is a failure for the value, the CLI will have already terminated with an error message."file"
for--location
, the internal origin will be the URL derived opaque origin for that URL.--config
flag was set at startup, the internal origin will be set to the URL derived opaque origin of the fully qualified URL of the value of the--config
value. (e.g. the location of the config file generates a unique opaque origin)Examples:
deno run --location https://deno.land/x/example.ts main.ts
["https", "deno.land", null, null]
deno run --location file:///a/test.ts main.ts
"file:///a/test.ts"
deno run --location https://example.com/ --config tsconfig.json main.ts
["https", "example.com", null, null]
deno run --config tsconfig.json main.ts
tsconfig.json
deno run main.ts
main.ts
deno run /User/example/project/main.ts
file:///User/example/project/
deno test /User/example/project/test.ts
file:///User/example/project/
deno run /User/example/project/lib/lib.ts
file:///User/example/project/lib/
deno run https://deno.land/x/example/mod.ts
https://deno.land/x/example/
Implications:
window.location
.URL derived opaque origins
The Deno CLI will have the concept of URL derived opaque origins. This is a concept that a unique opaque origin can be derived from a normalized string serialization of a URL and this unique opaque origin will reproducible from invocation to invocation of the Deno CLI and irrespective of host.
For example, the string URL of
https://deno.land/x/example/mod.ts
could be converted into a unique opaque origin that would be not equal to an opaque origin converted fromhttps://deno.land/x/example/lib.ts
, but every Deno CLI executable would perform the conversion in a consistent fashion so that a persisted version of the unique origin could be considered equal to recently converted one.For simplicity, it is likely that the string representation of the URL that the opaque origin is being derived from is used, as it ensures the same opaque origin could be used and makes for simplistic equality checking, though whenever exposed "externally" it needs to be serialized as
null
. In a JavaScript isolate, this simply could something like this:The text was updated successfully, but these errors were encountered: