Skip to content

Conversation

@LinuxSuRen
Copy link
Owner

@LinuxSuRen LinuxSuRen commented Aug 24, 2025

  • feat: add extension to getting page of static
  • fix some issue of getting static files

We highly recommend you read the contributor's documentation before starting the review process especially since this is your first contribution to this project.

It was updated on 2024/5/27

What type of PR is this?

What this PR does / why we need it:
LinuxSuRen/atest-ext-store-mermaid#2 implemented the static file extension point.

Which issue(s) this PR fixes:

Fixes #

@LinuxSuRen LinuxSuRen added the enhancement New feature or request label Aug 24, 2025
@github-actions
Copy link

github-actions bot commented Aug 24, 2025

There are 1 test cases, failed count 0:

Name Average Max Min Count Error
11.883999ms 12.259602ms 11.595722ms 3 0

Reported by api-testing.

Name: pathParams["data"],
})
if err == nil {
w.Write([]byte(result.GetMessage()))

Check warning

Code scanning / CodeQL

Reflected cross-site scripting Medium

Cross-site scripting vulnerability due to
user-provided value
.

Copilot Autofix

AI 2 months ago

To address the XSS vulnerability, we should escape any untrusted data before embedding it in an HTTP response likely to be rendered as HTML by browsers. In this case, the output from result.GetMessage() should be HTML-escaped, especially since extension code receives arbitrary header values from the user and could include them in the message.

Best fix:

  • In the handler function, change the line that writes the message to the response to write the HTML-escaped version of the message.
  • Use Go's standard html.EscapeString() function (import "html" package) for HTML escaping.
  • Only the relevant region of cmd/server.go needs to be changed: around line 549, and a new import added at the top.

No changes are required to the proto or server files; only the handler that produces the HTTP response needs adjusting.

Suggested changeset 1
cmd/server.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/cmd/server.go b/cmd/server.go
--- a/cmd/server.go
+++ b/cmd/server.go
@@ -32,7 +32,7 @@
 	"strings"
 	"syscall"
 	"time"
-
+	"html"
 	"github.com/linuxsuren/api-testing/pkg/apispec"
 
 	"github.com/linuxsuren/api-testing/pkg/runner"
@@ -546,9 +546,9 @@
 			Name: pathParams["data"],
 		})
 		if err == nil {
-			w.Write([]byte(result.GetMessage()))
+			w.Write([]byte(html.EscapeString(result.GetMessage())))
 		} else {
-			w.Write([]byte(err.Error()))
+			w.Write([]byte(html.EscapeString(err.Error())))
 		}
 	}
 }
EOF
@@ -32,7 +32,7 @@
"strings"
"syscall"
"time"

"html"
"github.com/linuxsuren/api-testing/pkg/apispec"

"github.com/linuxsuren/api-testing/pkg/runner"
@@ -546,9 +546,9 @@
Name: pathParams["data"],
})
if err == nil {
w.Write([]byte(result.GetMessage()))
w.Write([]byte(html.EscapeString(result.GetMessage())))
} else {
w.Write([]byte(err.Error()))
w.Write([]byte(html.EscapeString(err.Error())))
}
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
@codacy-production
Copy link

codacy-production bot commented Aug 24, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.53% (target: -1.00%) 23.79% (target: 80.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (30d03eb) 21785 8219 37.73%
Head commit (f228dd2) 22353 (+568) 8552 (+333) 38.26% (+0.53%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#814) 206 49 23.79%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@sonarqubecloud
Copy link

@LinuxSuRen LinuxSuRen merged commit ce1f79f into master Aug 24, 2025
24 of 29 checks passed
@LinuxSuRen LinuxSuRen deleted the feat/ext-page-of-static branch August 24, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants