Skip to content
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

Add "validate share data" algorithm #185

Merged
merged 38 commits into from
Aug 17, 2021
Merged
Changes from 11 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dbbc9df
Add canShare() method
marcoscaceres Sep 18, 2020
a3a4319
add SecureContext and allowed to use check
marcoscaceres Sep 21, 2020
99cccb7
Add http+https checks to validation
marcoscaceres Sep 21, 2020
c60193b
Handle empty files sequence
marcoscaceres Sep 23, 2020
a1a8a8b
Update index.html
marcoscaceres Sep 23, 2020
e04fca8
Merge branch 'master' into canShare
marcoscaceres Sep 23, 2020
7dde1f3
Merge branch 'master' into canShare
marcoscaceres Sep 24, 2020
a42f0b7
Add "validate share data" algorithm
marcoscaceres Sep 23, 2020
84e8c3a
fixup
marcoscaceres Sep 28, 2020
bd53f07
Simplify call to validate share data
marcoscaceres Sep 28, 2020
e683d56
Apply suggestions from code review
marcoscaceres Oct 14, 2020
788a9e2
Merge branch 'master' into validate_data
marcoscaceres Oct 28, 2020
6c0a9f5
Add AU-specific type check, plus reject
marcoscaceres Oct 28, 2020
daa015a
Merge branch 'main' into validate_data
marcoscaceres Jun 17, 2021
6654681
Merge branch 'main' into validate_data
marcoscaceres Aug 8, 2021
1adf6dc
Merge branch 'main' into validate_data
marcoscaceres Aug 8, 2021
bae0c90
Merge branch 'main' into validate_data
marcoscaceres Aug 8, 2021
b494946
Fixup internal slot
marcoscaceres Aug 8, 2021
88865d6
Merge branch 'main' into validate_data
marcoscaceres Aug 9, 2021
f83e582
Merge branch 'main' into validate_data
marcoscaceres Aug 9, 2021
95d9909
Update index.html
marcoscaceres Aug 16, 2021
40618ca
Remove note about allowed to use in priv sec section
marcoscaceres Aug 16, 2021
32eaf09
Merge branch 'main' into validate_data
marcoscaceres Aug 16, 2021
1355ab6
Merge branch 'main' into validate_data
marcoscaceres Aug 16, 2021
abd6bcd
Fixup + remove link to issue 127
marcoscaceres Aug 16, 2021
28e5ad5
fixup typo
marcoscaceres Aug 16, 2021
d86d782
another typo
marcoscaceres Aug 16, 2021
e72fe88
Add missing {{DOMException}} in places
marcoscaceres Aug 16, 2021
f79f7c6
Merge branch 'main' into validate_data
marcoscaceres Aug 16, 2021
a978ab3
Merge branch 'main' into validate_data
marcoscaceres Aug 16, 2021
5b7071e
Remove null check, done elsewhere
marcoscaceres Aug 16, 2021
c03d6ab
Merge branch 'main' into validate_data
marcoscaceres Aug 16, 2021
c8c2525
Remove ref to secure-context
marcoscaceres Aug 16, 2021
b563520
Further fixup
marcoscaceres Aug 16, 2021
a612457
Merge branch 'main' into validate_data
marcoscaceres Aug 17, 2021
9d2f37b
Let UA decide what's a hostile URL
marcoscaceres Aug 17, 2021
5ca9b3a
Merge branch 'main' into validate_data
marcoscaceres Aug 17, 2021
892497f
Include issue 178
marcoscaceres Aug 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 66 additions & 25 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
};
</script>
</head>
<body data-cite="FILEAPI">
<body data-cite="FILEAPI secure-contexts">
<section id="abstract">
<p>
This specification defines an API for sharing text, links and other
Expand Down Expand Up @@ -147,7 +147,7 @@ <h4>
<ol class="algorithm">
<li>If the current settings object's responsible document is not
<a>allowed to use</a> the "[=web-share-feature|web-share=]"
permission, return [=a promise rejected with=] with a
permission, return [=a promise rejected with=] a
{{"NotAllowedError"}} {{DOMException}}.
</li>
<li>If {{[[sharePromise]]}} is not `null`, return <a>a promise
Expand All @@ -161,32 +161,21 @@ <h4>
</li>
<li>[=Consume user activation=] of |window|.
</li>
<li>If none of |data|'s members {{ShareData/title}},
{{ShareData/text}}, or {{ShareData/url}} or {{ShareData/file}} are
present, return <a>a promise rejected with</a> a {{TypeError}}.
<li>If {{[[sharePromise]]}} is not `null`, return [=a promise
rejected with=] {{InvalidStateError}}.
</li>
<li>If |data|'s {{ShareData/files}} member is present:
<ol>
<li>If |data|'s {{ShareData/files}} member is empty, or if the
implementation does not support file sharing, return <a>a
promise rejected with</a> a {{TypeError}}, and abort these
steps.
</li>
</ol>
<li>Let |base:URL| be the [=this=] value's <a>relevant settings
object</a>'s [=environment settings object/api base URL=].
</li>
<li>If [=validate share data=] with |data| and |base| returns
false, then return [=a promise rejected with=] a {{TypeError}}.
</li>
<li>If |data|'s {{ShareData/url}} member is present:
<ol>
<li>Let |base:URL| be the [=this=] value's <a>relevant settings
object</a>'s [=environment settings object/api base URL=].
</li>
<li>Let |url:URL| be the result of running the <a>URL
parser</a> on |data|'s {{ShareData/url}} with |base|.
</li>
<li>If |url| is failure, return <a>a promise rejected with</a>
{{TypeError}}.
</li>
<li>If |url|'s [=URL/scheme=] is not "http" or "https", return
<a>a promise rejected with</a> {{TypeError}}.
<li>Assert: |url| is {{URL}}.
</li>
<li>Set |data| to a copy of |data|, with its {{ShareData/url}}
member set to the result of running the <a>URL serializer</a>
Expand All @@ -195,7 +184,7 @@ <h4>
</ol>
</li>
<li>If a file type is being blocked due to security considerations,
return <a>a promise rejected with</a> with a {{"NotAllowedError"}}
return [=a promise rejected with=] with a {{"NotAllowedError"}}
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
{{DOMException}}.
</li>
<li>Set {{[[sharePromise]]}} to be <a>a new promise</a>.
Expand Down Expand Up @@ -269,6 +258,55 @@ <h4>
or bypassing the UI if there is only a single share target.
</div>
</section>
<section>
<h3>
Validate share data
</h3>
<p>
To <dfn>validate share data</dfn> with |data:ShareData| and
|base:URL|, run the following steps:
</p>
<ol class="algorithm">
<li>If none of |data|'s members {{ShareData/title}},
{{ShareData/text}}, or {{ShareData/url}} or {{ShareData/files}} are
present, return false.
</li>
<li>Let |titleTextOrUrl:boolean| be true if any of
{{ShareData/title}}, or {{ShareData/text}}, or {{ShareData/url}} is
present.
</li>
<li>If |data|'s {{ShareData/files}} member is present:
<ol>
<li>If |titleTextOrUrl| is false and |data|'s
{{ShareData/files}} member is empty, return false.
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
<p class="note">
This causes a `{ files: [] }` dictionary to be treated as
an empty dictionary. However, passing a dictionary like
`{text: "text", files: []}` is fine, as `files` is just
ignored.
</p>
</li>
<li>If the implementation does not support file sharing, return
false.
</li>
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
</ol>
</li>
<li>If |data|'s url member is present:
<ol>
<li>Let |url:URL| be the result of running the [=URL parser=]
on |data|'s url, with |base|, and no encoding override.
</li>
<li>If |url| is failure, return false.
</li>
<li>If |url|'s [=URL/scheme=] is not "http" or "https", return
false.
</li>
</ol>
</li>
<li>Return true.
</li>
</ol>
</section>
</section>
<section data-dfn-for="ShareData">
<h3>
Expand Down Expand Up @@ -459,9 +497,13 @@ <h2>
native applications.
</li>
<li>Due to the capabilities of the API surface, {{Navigator/share()}}
is <a>available only in secure contexts</a> (such as `https://`
method is restricted to [=secure contexts=] (such as `https://`
schemes).
</li>
<li>Third-party contexts require that they be [=allowed to use=] the
{{Navigator/share()}} method is one of the mechanisms described in
[[[permissions-policy]]].
marcoscaceres marked this conversation as resolved.
Show resolved Hide resolved
</li>
<li>Use of {{Navigator/share()}} from a <a href=
"https://en.wikipedia.org/wiki/Privacy_mode">private browsing mode</a>
might leak private data to a third-party application that does not
Expand Down Expand Up @@ -508,8 +550,7 @@ <h2>
when information should be confidential, so forwarding any content
presents a risk. In particular, the {{ShareData/title}} might be
used by an attacker to trick a user into misinterpreting the nature
of the content.
<!--
of the content. <!--
, as demonstrated in the [[Wylecial]] <a data-cite=
"Wylecial#">proof of concept attack</a>
-->
Expand Down