go/src
Roland Shoemaker bbd043ff0d [release-branch.go1.21] html/template: properly handle special tags within the script context
The HTML specification has incredibly complex rules for how to handle
"<!--", "<script", and "</script" when they appear within literals in
the script context. Rather than attempting to apply these restrictions
(which require a significantly more complex state machine) we apply
the workaround suggested in section 4.12.1.3 of the HTML specification [1].

More precisely, when "<!--", "<script", and "</script" appear within
literals (strings and regular expressions, ignoring comments since we
already elide their content) we replace the "<" with "\x3C". This avoids
the unintuitive behavior that using these tags within literals can cause,
by simply preventing the rendered content from triggering it. This may
break some correct usages of these tags, but on balance is more likely
to prevent XSS attacks where users are unknowingly either closing or not
closing the script blocks where they think they are.

Thanks to Takeshi Kaneko (GMO Cybersecurity by Ierae, Inc.) for
reporting this issue.

Fixes #62197
Fixes #62398
Fixes CVE-2023-39319

[1] https://html.spec.whatwg.org/#restrictions-for-contents-of-script-elements

Change-Id: Iab57b0532694827e3eddf57a7497ba1fab1746dc
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1976594
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2014619
Reviewed-on: https://go-review.googlesource.com/c/go/+/526097
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-06 14:20:20 +00:00
..
archive
arena
bufio
builtin cmp, builtin: document NaN behavior 2023-06-11 00:41:42 +00:00
bytes bytes: remove builders check from compare test 2023-07-13 23:11:42 +00:00
cmd [release-branch.go1.21] cmd/go: reject toolchain directives containing path separators 2023-09-06 14:19:53 +00:00
cmp cmp, builtin: document NaN behavior 2023-06-11 00:41:42 +00:00
compress compress/bzip2: fix typo 2023-06-16 18:24:46 +00:00
container
context [release-branch.go1.21] context: fix synchronization in ExampleAfterFunc_cond 2023-08-24 21:13:14 +00:00
crypto [release-branch.go1.21] crypto/tls: QUIC: fix panics when processing post-handshake messages 2023-08-30 21:27:45 +00:00
database/sql src/database/sql: run gofmt 2023-07-07 20:48:55 +00:00
debug
embed
encoding [release-branch.go1.21] encoding/xml: overriding by empty namespace when no new name declaration 2023-08-30 20:17:11 +00:00
errors
expvar
flag
fmt
go [release-branch.go1.21] html/template: properly handle special tags within the script context 2023-09-06 14:20:20 +00:00
hash all: fix spelling errors 2023-06-14 00:03:57 +00:00
html [release-branch.go1.21] html/template: properly handle special tags within the script context 2023-09-06 14:20:20 +00:00
image
index/suffixarray
internal [release-branch.go1.21] go/types, types2: remove order dependency in inference involving channels 2023-08-30 21:35:21 +00:00
io
log [release-branch.go1.21] log/slog: fix comment above log levels 2023-07-24 17:02:06 +00:00
maps [release-branch.go1.21] maps: remove Keys and Values 2023-07-27 22:20:27 +00:00
math math: test large negative values as args for trig functions 2023-07-17 21:05:34 +00:00
mime all: fix spelling errors 2023-06-14 00:03:57 +00:00
net [release-branch.go1.21] net/http: revert "support streaming POST content in wasm" 2023-08-31 16:40:31 +00:00
os [release-branch.go1.21] Revert "os: use handle based APIs to read directories on windows" 2023-08-23 19:57:00 +00:00
path [release-branch.go1.21] path/filepath: don't drop .. elements when cleaning invalid Windows paths 2023-08-23 17:53:26 +00:00
plugin
reflect reflect: fix ArenaNew to match documentation 2023-06-16 17:08:43 +00:00
regexp
runtime [release-branch.go1.21] runtime: restore caller's frame pointer when recovering from panic 2023-08-30 22:33:03 +00:00
slices slices, maps: add examples; doc comment fixes 2023-06-29 15:34:32 +00:00
sort sort: comments directing new code to use the slices package when applicable 2023-06-13 18:07:00 +00:00
strconv
strings
sync
syscall syscall: serialize locks on ForkLock on platforms where forkExecPipe is not atomic 2023-07-10 19:19:59 +00:00
testdata
testing testing/slogtest: check for no group with empty record 2023-07-11 20:08:28 +00:00
text text/template: set variables correctly in range assignment 2023-06-15 14:28:01 +00:00
time time: increase arbitrary upper bound in TestReset to 10s 2023-07-11 13:19:40 +00:00
unicode
unsafe
vendor all: update vendored dependencies 2023-07-12 20:38:21 +00:00
Make.dist
README.vendor src/README.vendor: s/latest/master/ 2023-07-11 21:30:51 +00:00
all.bash
all.bat
all.rc
bootstrap.bash
buildall.bash
clean.bash
clean.bat
clean.rc
cmp.bash
go.mod all: update vendored dependencies 2023-07-12 20:38:21 +00:00
go.sum all: update vendored dependencies 2023-07-12 20:38:21 +00:00
make.bash
make.bat
make.rc
race.bash
race.bat
run.bash
run.bat
run.rc

README.vendor

Vendoring in std and cmd
========================

The Go command maintains copies of external packages needed by the
standard library in the src/vendor and src/cmd/vendor directories.

There are two modules, std and cmd, defined in src/go.mod and
src/cmd/go.mod. When a package outside std or cmd is imported
by a package inside std or cmd, the import path is interpreted
as if it had a "vendor/" prefix. For example, within "crypto/tls",
an import of "golang.org/x/crypto/cryptobyte" resolves to
"vendor/golang.org/x/crypto/cryptobyte". When a package with the
same path is imported from a package outside std or cmd, it will
be resolved normally. Consequently, a binary may be built with two
copies of a package at different versions if the package is
imported normally and vendored by the standard library.

Vendored packages are internally renamed with a "vendor/" prefix
to preserve the invariant that all packages have distinct paths.
This is necessary to avoid compiler and linker conflicts. Adding
a "vendor/" prefix also maintains the invariant that standard
library packages begin with a dotless path element.

The module requirements of std and cmd do not influence version
selection in other modules. They are only considered when running
module commands like 'go get' and 'go mod vendor' from a directory
in GOROOT/src.

Maintaining vendor directories
==============================

Before updating vendor directories, ensure that module mode is enabled.
Make sure that GO111MODULE is not set in the environment, or that it is
set to 'on' or 'auto'.

Requirements may be added, updated, and removed with 'go get'.
The vendor directory may be updated with 'go mod vendor'.
A typical sequence might be:

    cd src
    go get golang.org/x/net@master
    go mod tidy
    go mod vendor

Use caution when passing '-u' to 'go get'. The '-u' flag updates
modules providing all transitively imported packages, not only
the module providing the target package.

Note that 'go mod vendor' only copies packages that are transitively
imported by packages in the current module. If a new package is needed,
it should be imported before running 'go mod vendor'.