Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ on:
'**/*.wgsl'
]

permissions:
contents: read

Comment on lines +50 to +52
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
cancel-in-progress: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-metal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Build
id: cmake_build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server-webui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Setup Node.js
id: node
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Build
id: cmake_build
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Build
id: cmake_build
Expand Down
21 changes: 18 additions & 3 deletions scripts/serve-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ const mimeTypes = {
'.woff2': 'font/woff2',
};

function escapeHtml(value) {
return value
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#39;');
}

async function generateDirListing(dirPath, reqUrl) {
const files = await fs.readdir(dirPath);
let html = `
Expand All @@ -40,7 +49,7 @@ async function generateDirListing(dirPath, reqUrl) {
</style>
</head>
<body>
<h1>Directory: ${reqUrl}</h1>
<h1>Directory: ${escapeHtml(reqUrl)}</h1>
<ul>
`;

Expand All @@ -52,7 +61,7 @@ async function generateDirListing(dirPath, reqUrl) {
const filePath = path.join(dirPath, file);
const stats = await fs.stat(filePath);
const link = encodeURIComponent(file) + (stats.isDirectory() ? '/' : '');
html += `<li><a href="${link}">${file}${stats.isDirectory() ? '/' : ''}</a></li>`;
html += `<li><a href="${link}">${escapeHtml(file)}${stats.isDirectory() ? '/' : ''}</a></li>`;
}

html += `
Expand All @@ -72,7 +81,13 @@ const server = http.createServer(async (req, res) => {
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');

const filePath = path.join(STATIC_DIR, decodeURIComponent(req.url));
const requestPath = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
const filePath = path.resolve(STATIC_DIR, `.${requestPath}`);
if (filePath !== STATIC_DIR && !filePath.startsWith(`${STATIC_DIR}${path.sep}`)) {
Comment on lines +84 to +86
res.writeHeader(403, { 'Content-Type': 'text/plain' });
res.end('403 Forbidden');
return;
}
const stats = await fs.stat(filePath);

if (stats.isDirectory()) {
Expand Down
2 changes: 1 addition & 1 deletion tools/server/public_simplechat/simplechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ class MultiChatUI {
}
this.handle_user_submit(this.curChatId, gMe.apiEP).catch((/** @type{Error} */reason)=>{
let msg = `ERRR:SimpleChat\nMCUI:HandleUserSubmit:${this.curChatId}\n${reason.name}:${reason.message}`;
console.error(msg.replace("\n", ":"));
console.error(msg.replace(/\n/g, ":"));
alert(msg);
this.ui_reset_userinput();
});
Expand Down
Loading