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

fix(codeQL): Patched code #4

Merged
merged 9 commits into from
Dec 17, 2023
Merged
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
81 changes: 0 additions & 81 deletions .github/workflows/codeql.yml

This file was deleted.

8 changes: 6 additions & 2 deletions src/endpoints/file.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Application, Request, Response } from "express";
import { apiMessage, errorMessage } from "../logger";
import { existsSync } from "fs";
import { join } from "path";
import { resolve } from "path";

export default (app: Application) => {
app.get("/:name", async (req: Request, res: Response) => {
try {
const fileName = req.params.name;
apiMessage(req.path, `User is trying to get a file - ${fileName}`);
const filePath = join(__dirname, "../", "files", fileName);
const fileNamePattern = /^[a-zA-Z0-9_-]+$/;
if (!fileNamePattern.test(fileName)) {
return res.status(400).json({ error: "Invalid file name" });
}
const filePath = resolve(__dirname, "../", "files", fileName);
if (!existsSync(filePath)) {
errorMessage(`File ${fileName} not found`);
return res
Expand Down
4 changes: 4 additions & 0 deletions src/endpoints/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default (app: Application) => {
}

const fileName = req.params.name;
const fileNamePattern = /^[a-zA-Z0-9_-]+$/;
if (!fileNamePattern.test(fileName)) {
return res.status(400).json({ error: "Invalid file name" });
}
const filePath = join(__dirname, "../", "files", fileName);
if (existsSync(filePath)) {
errorMessage(`File ${fileName} already exists`);
Expand Down
Loading