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

[CI] Fix xharness local run. #22236

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Changes from all commits
Commits
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
41 changes: 40 additions & 1 deletion tests/xharness/Jenkins/TestServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ namespace Xharness.Jenkins {

class TestServer {

static IReadOnlySet<string> AllowedPaths = new HashSet<string> (StringComparer.Ordinal) {
"/",
"/index.html",
"/set-option",
"/select",
"/deselect",
"/stop",
"/run",
"/build",
"/reload-devices",
"/reload-simulators",
"/quit",
"/favicon.ico",
"/index.html",
};

static IReadOnlySet<string> AllowedFiles = new HashSet<string> (StringComparer.Ordinal) {
"index.html",
"xharness.css",
"xharness.js",
};



Comment on lines +18 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here, and there are a few extra blank lines.

public Task RunAsync (Jenkins jenkins, HtmlReportWriter htmlReportWriter)
{
HttpListener server;
Expand Down Expand Up @@ -95,8 +119,23 @@ IEnumerable<ITestTask> find_tasks (StreamWriter writer, string ids)
}

string serveFile = null;
// do not allow requests that are not http or https
if (request.Url.Scheme != Uri.UriSchemeHttp && request.Url.Scheme != Uri.UriSchemeHttps) {
response.StatusCode = 400;
response.StatusDescription = "Bad Request";
response.OutputStream.Write (System.Text.Encoding.UTF8.GetBytes ("Invalid local path"));
return;
}
var localPath = request.Url.LocalPath;
if (localPath.Contains ("..") || localPath.Contains ("/") || localPath.Contains ("\\")) {
var file = Path.GetFileName (localPath);
var directoryName = Path.GetDirectoryName (localPath);
var jenkinsDirectoryName = $"/{Path.GetFileName (jenkins.LogDirectory)}";

// for the request to be valid the local path has to be one of the following
// 1. local path should be one of the supported ones
// 2. Be index.html
// 3. Its directory name be the same as the log directory name, no other directory is allowed
if (!AllowedPaths.Contains (localPath) && !AllowedFiles.Contains (file) && !directoryName.StartsWith (jenkinsDirectoryName)) {
// Validate that we're not requested to serve any file on the file system.
// Ref: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2351243
response.StatusCode = 400;
Expand Down
Loading