From fc0e2bd566a8e8777acc824211f6027184840a49 Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Fri, 4 Aug 2023 03:24:13 +0800 Subject: [PATCH 1/2] [Backport] html/template: support HTML-like comments in script contexts Reference: https://open.codehub.huawei.com/OpenSourceCenter/golang/go/merge_requests/89 Conflict: NA Per Appendix B.1.1 of the ECMAScript specification, support HTML-like comments in script contexts. Also per section 12.5, support hashbang comments. This brings our parsing in-line with how browsers treat these comment types. Thanks to Takeshi Kaneko (GMO Cybersecurity by Ierae, Inc.) for reporting this issue. Note: The upstream does not submit this change to go1.17 according to the rules of MinorReleases. Corego3.x are based on go1.17.8. Therefore, it need to submit the change to corego3.x. Edited-by: machangwang m00509938 Fixes #62196 Fixes #62395 Fixes CVE-2023-39318 Change-Id: Id512702c5de3ae46cf648e268cb10e1eb392a181 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1976593 Run-TryBot: Roland Shoemaker Reviewed-by: Tatiana Bradley Reviewed-by: Damien Neil Reviewed-by: Dmitri Shuralyov Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2014620 Reviewed-on: https://go-review.googlesource.com/c/go/+/526098 Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Signed-off-by: Ma Chang Wang machangwang@huawei.com --- src/html/template/context.go | 6 ++- src/html/template/escape.go | 5 +- src/html/template/escape_test.go | 10 ++++ src/html/template/state_string.go | 26 +++++----- src/html/template/transition.go | 80 ++++++++++++++++++++----------- 5 files changed, 84 insertions(+), 43 deletions(-) diff --git a/src/html/template/context.go b/src/html/template/context.go index a67b5a7871..472b5a9772 100644 --- a/src/html/template/context.go +++ b/src/html/template/context.go @@ -124,6 +124,10 @@ const ( stateJSBlockCmt // stateJSLineCmt occurs inside a JavaScript // line comment. stateJSLineCmt + // stateJSHTMLOpenCmt occurs inside a JavaScript HTML-like comment. + stateJSHTMLCloseCmt // stateCSS occurs inside a