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

Pull from main to Move-InsightsAndSettingsLogic-to-component #377

Merged
merged 45 commits into from
Dec 17, 2024

Conversation

Tr01ler
Copy link
Contributor

@Tr01ler Tr01ler commented Dec 17, 2024

No description provided.

renatodellosso and others added 30 commits December 5, 2024 17:35
Bumps [next](https://github.com/vercel/next.js) from 15.0.3 to 15.1.0.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v15.0.3...v15.1.0)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
…/next-15.1.0

[npm]: Bump next from 15.0.3 to 15.1.0
…implement bulk user and pit report retrieval in ClientApi
renatodellosso and others added 15 commits December 14, 2024 11:53
Bumps [react-icons](https://github.com/react-icons/react-icons) from 5.3.0 to 5.4.0.
- [Release notes](https://github.com/react-icons/react-icons/releases)
- [Commits](react-icons/react-icons@v5.3.0...v5.4.0)

---
updated-dependencies:
- dependency-name: react-icons
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [daisyui](https://github.com/saadeghi/daisyui) from 4.12.14 to 4.12.22.
- [Release notes](https://github.com/saadeghi/daisyui/releases)
- [Changelog](https://github.com/saadeghi/daisyui/blob/master/CHANGELOG.md)
- [Commits](saadeghi/daisyui@v4.12.14...v4.12.22)

---
updated-dependencies:
- dependency-name: daisyui
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
…/daisyui-4.12.22

[npm]: Bump daisyui from 4.12.14 to 4.12.22
Bumps [@eslint/js](https://github.com/eslint/eslint/tree/HEAD/packages/js) from 9.16.0 to 9.17.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/commits/v9.17.0/packages/js)

---
updated-dependencies:
- dependency-name: "@eslint/js"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
…/react-icons-5.4.0

[npm]: Bump react-icons from 5.3.0 to 5.4.0
Bumps [@slack/web-api](https://github.com/slackapi/node-slack-sdk) from 7.7.0 to 7.8.0.
- [Release notes](https://github.com/slackapi/node-slack-sdk/releases)
- [Commits](https://github.com/slackapi/node-slack-sdk/compare/@slack/[email protected]...@slack/[email protected])

---
updated-dependencies:
- dependency-name: "@slack/web-api"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
…/eslint/js-9.17.0

[npm]: Bump @eslint/js from 9.16.0 to 9.17.0
Bumps [@yudiel/react-qr-scanner](https://github.com/yudielcurbelo/react-qr-scanner) from 2.0.8 to 2.1.0.
- [Release notes](https://github.com/yudielcurbelo/react-qr-scanner/releases)
- [Commits](yudielcurbelo/react-qr-scanner@v2.0.8...v2.1.0)

---
updated-dependencies:
- dependency-name: "@yudiel/react-qr-scanner"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
…/slack/web-api-7.8.0

[npm]: Bump @slack/web-api from 7.7.0 to 7.8.0
…/yudiel/react-qr-scanner-2.1.0

[npm]: Bump @yudiel/react-qr-scanner from 2.0.8 to 2.1.0
.finally(() => {
if (location.href.includes("offline"))
location.href = `/offline/${props.compId}`;
else location.href = `/${teamSlug}/${seasonSlug}/${competitonSlug}`;

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix AI 3 months ago

To fix the problem, we need to ensure that the URL redirection only uses trusted and validated values. One way to achieve this is by maintaining a list of authorized redirects and choosing from that list based on the user input provided. This approach ensures that only predefined and safe URLs are used for redirection.

We will create a list of authorized redirects and use a function to validate the teamSlug, seasonSlug, and competitonSlug values against this list before performing the redirection. If the values are not valid, we can redirect to a default safe URL or show an error message.

Suggested changeset 1
pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/subjective.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/subjective.tsx b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/subjective.tsx
--- a/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/subjective.tsx
+++ b/pages/[teamSlug]/[seasonSlug]/[competitonSlug]/[reportId]/subjective.tsx
@@ -117,5 +117,17 @@
 			.finally(() => {
-				if (location.href.includes("offline"))
+				if (location.href.includes("offline")) {
 					location.href = `/offline/${props.compId}`;
-				else location.href = `/${teamSlug}/${seasonSlug}/${competitonSlug}`;
+				} else {
+					const authorizedRedirects = [
+						`/${teamSlug}/${seasonSlug}/${competitonSlug}`,
+						// Add other authorized redirects here
+					];
+					const redirectUrl = `/${teamSlug}/${seasonSlug}/${competitonSlug}`;
+					if (authorizedRedirects.includes(redirectUrl)) {
+						location.href = redirectUrl;
+					} else {
+						// Redirect to a default safe URL or show an error message
+						location.href = '/default-safe-url';
+					}
+				}
 			});
EOF
@@ -117,5 +117,17 @@
.finally(() => {
if (location.href.includes("offline"))
if (location.href.includes("offline")) {
location.href = `/offline/${props.compId}`;
else location.href = `/${teamSlug}/${seasonSlug}/${competitonSlug}`;
} else {
const authorizedRedirects = [
`/${teamSlug}/${seasonSlug}/${competitonSlug}`,
// Add other authorized redirects here
];
const redirectUrl = `/${teamSlug}/${seasonSlug}/${competitonSlug}`;
if (authorizedRedirects.includes(redirectUrl)) {
location.href = redirectUrl;
} else {
// Redirect to a default safe URL or show an error message
location.href = '/default-safe-url';
}
}
});
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
highWaterMark: 256 * 1024,
});
res.writeHead(200, { "content-type": "image/*" });
var s = fs.createReadStream(process.env.IMAGE_UPLOAD_DIR + `/${filename}`, {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 3 months ago

To fix the problem, we need to ensure that the constructed file path is contained within a safe root directory. This can be achieved by normalizing the path using path.resolve and then checking that the normalized path starts with the root directory. If the path is not within the root directory, we should return an error response.

  1. Import the path module.
  2. Normalize the constructed file path using path.resolve.
  3. Check if the normalized path starts with the root directory (process.env.IMAGE_UPLOAD_DIR).
  4. If the path is valid, proceed with reading the file. Otherwise, return a 403 error response.
Suggested changeset 1
pages/api/img/get.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pages/api/img/get.ts b/pages/api/img/get.ts
--- a/pages/api/img/get.ts
+++ b/pages/api/img/get.ts
@@ -2,2 +2,3 @@
 import * as fs from "fs";
+import * as path from "path";
 
@@ -17,4 +18,11 @@
 
+		const rootDir = process.env.IMAGE_UPLOAD_DIR;
+		const filePath = path.resolve(rootDir, filename);
+
+		if (!filePath.startsWith(rootDir)) {
+			return res.status(403).send({ status: 403, message: "Forbidden" });
+		}
+
 		res.writeHead(200, { "content-type": "image/*" });
-		var s = fs.createReadStream(process.env.IMAGE_UPLOAD_DIR + `/${filename}`, {
+		var s = fs.createReadStream(filePath, {
 			highWaterMark: 256 * 1024,
EOF
@@ -2,2 +2,3 @@
import * as fs from "fs";
import * as path from "path";

@@ -17,4 +18,11 @@

const rootDir = process.env.IMAGE_UPLOAD_DIR;
const filePath = path.resolve(rootDir, filename);

if (!filePath.startsWith(rootDir)) {
return res.status(403).send({ status: 403, message: "Forbidden" });
}

res.writeHead(200, { "content-type": "image/*" });
var s = fs.createReadStream(process.env.IMAGE_UPLOAD_DIR + `/${filename}`, {
var s = fs.createReadStream(filePath, {
highWaterMark: 256 * 1024,
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
} else {
return res.send({ status: 400, message: "Invalid Request" });
}
var tempFile = fs.readFileSync(file.filepath, { encoding: "base64" });

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 3 months ago

To fix the problem, we need to ensure that the file path derived from user input is validated and sanitized before being used. We can achieve this by normalizing the path and ensuring it is contained within a designated safe directory. This involves using path.resolve to normalize the path and then checking that the resulting path starts with the intended root directory.

Suggested changeset 1
pages/api/img/upload.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pages/api/img/upload.ts b/pages/api/img/upload.ts
--- a/pages/api/img/upload.ts
+++ b/pages/api/img/upload.ts
@@ -3,3 +3,3 @@
 import * as fs from "fs";
-
+import * as path from "path";
 export const config = {
@@ -26,9 +26,16 @@
 
+			const ROOT = process.env.IMAGE_UPLOAD_DIR;
 			var filetype = file.mimetype.split("image/")[1];
 			var filename = `/${file.newFilename}.${filetype}`;
-			console.log(process.env.IMAGE_UPLOAD_DIR + filename);
-			console.log(process.env.IMAGE_UPLOAD_DIR);
+			var filePath = path.resolve(ROOT, filename);
+
+			if (!filePath.startsWith(ROOT)) {
+				throw new Error("Invalid file path");
+			}
+
+			console.log(filePath);
+			console.log(ROOT);
 
 			var tempFile = fs.readFileSync(file.filepath, { encoding: "base64" });
-			fs.writeFile(process.env.IMAGE_UPLOAD_DIR + filename, tempFile, (err) => {
+			fs.writeFile(filePath, tempFile, (err) => {
 				res.send({ status: 200, filename: filename });
EOF
@@ -3,3 +3,3 @@
import * as fs from "fs";

import * as path from "path";
export const config = {
@@ -26,9 +26,16 @@

const ROOT = process.env.IMAGE_UPLOAD_DIR;
var filetype = file.mimetype.split("image/")[1];
var filename = `/${file.newFilename}.${filetype}`;
console.log(process.env.IMAGE_UPLOAD_DIR + filename);
console.log(process.env.IMAGE_UPLOAD_DIR);
var filePath = path.resolve(ROOT, filename);

if (!filePath.startsWith(ROOT)) {
throw new Error("Invalid file path");
}

console.log(filePath);
console.log(ROOT);

var tempFile = fs.readFileSync(file.filepath, { encoding: "base64" });
fs.writeFile(process.env.IMAGE_UPLOAD_DIR + filename, tempFile, (err) => {
fs.writeFile(filePath, tempFile, (err) => {
res.send({ status: 200, filename: filename });
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
return res.send({ status: 400, message: "Invalid Request" });
}
var tempFile = fs.readFileSync(file.filepath, { encoding: "base64" });
fs.writeFile(process.env.IMAGE_UPLOAD_DIR + filename, tempFile, (err) => {

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 3 months ago

To fix the problem, we need to ensure that the constructed file path is contained within a safe root folder. We can achieve this by normalizing the path using path.resolve and then checking that the normalized path starts with the root folder. This will prevent directory traversal attacks by ensuring that the file path does not escape the intended directory.

  1. Import the path module.
  2. Normalize the constructed file path using path.resolve.
  3. Check that the normalized path starts with the root folder (process.env.IMAGE_UPLOAD_DIR).
  4. If the check fails, return an error response.
  5. If the check passes, proceed with the file system operation.
Suggested changeset 1
pages/api/img/upload.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pages/api/img/upload.ts b/pages/api/img/upload.ts
--- a/pages/api/img/upload.ts
+++ b/pages/api/img/upload.ts
@@ -3,2 +3,3 @@
 import * as fs from "fs";
+import * as path from "path";
 
@@ -27,8 +28,15 @@
 			var filetype = file.mimetype.split("image/")[1];
-			var filename = `/${file.newFilename}.${filetype}`;
-			console.log(process.env.IMAGE_UPLOAD_DIR + filename);
-			console.log(process.env.IMAGE_UPLOAD_DIR);
+			var filename = `${file.newFilename}.${filetype}`;
+			var uploadDir = process.env.IMAGE_UPLOAD_DIR;
+			var filePath = path.resolve(uploadDir, filename);
+
+			if (!filePath.startsWith(uploadDir)) {
+				return res.send({ status: 403, message: "Forbidden" });
+			}
 
 			var tempFile = fs.readFileSync(file.filepath, { encoding: "base64" });
-			fs.writeFile(process.env.IMAGE_UPLOAD_DIR + filename, tempFile, (err) => {
+			fs.writeFile(filePath, tempFile, (err) => {
+				if (err) {
+					return res.send({ status: 500, message: err.message });
+				}
 				res.send({ status: 200, filename: filename });
EOF
@@ -3,2 +3,3 @@
import * as fs from "fs";
import * as path from "path";

@@ -27,8 +28,15 @@
var filetype = file.mimetype.split("image/")[1];
var filename = `/${file.newFilename}.${filetype}`;
console.log(process.env.IMAGE_UPLOAD_DIR + filename);
console.log(process.env.IMAGE_UPLOAD_DIR);
var filename = `${file.newFilename}.${filetype}`;
var uploadDir = process.env.IMAGE_UPLOAD_DIR;
var filePath = path.resolve(uploadDir, filename);

if (!filePath.startsWith(uploadDir)) {
return res.send({ status: 403, message: "Forbidden" });
}

var tempFile = fs.readFileSync(file.filepath, { encoding: "base64" });
fs.writeFile(process.env.IMAGE_UPLOAD_DIR + filename, tempFile, (err) => {
fs.writeFile(filePath, tempFile, (err) => {
if (err) {
return res.send({ status: 500, message: err.message });
}
res.send({ status: 200, filename: filename });
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@Tr01ler Tr01ler merged commit 570523b into Move-InsightsAndSettings-Logic-to-component Dec 17, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants