ctfguide-tech / CTFGuideNext

The new in-development client for CTFGuide built with Next.js.
https://ctfguide.com
Other
9 stars 8 forks source link

Sweep: Entering an invalid challenge ID in the URL still returns the page - but with empty content. #65

Closed kevinlu1248 closed 1 year ago

kevinlu1248 commented 1 year ago

Entering an invalid challenge ID in the URL still returns the page - but with empty content. It should instead redirect to a 404 page. Replica of https://github.com/ctfguide-tech/CTFGuideNext/issues/61.

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/ctfguide-tech/CTFGuideNext/pull/66


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze this snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/ctfguide-tech/CTFGuideNext/blob/96aa084249bd53b2c344ac804b4fc254f9a52727/src/pages/challenges/[slug].jsx#L221-L403 https://github.com/ctfguide-tech/CTFGuideNext/blob/96aa084249bd53b2c344ac804b4fc254f9a52727/src/pages/create.jsx#L14-L212 https://github.com/ctfguide-tech/CTFGuideNext/blob/96aa084249bd53b2c344ac804b4fc254f9a52727/src/pages/practice/hub.jsx#L1-L138 https://github.com/ctfguide-tech/CTFGuideNext/blob/96aa084249bd53b2c344ac804b4fc254f9a52727/src/pages/challenges/[slug].jsx#L127-L0 https://github.com/ctfguide-tech/CTFGuideNext/blob/96aa084249bd53b2c344ac804b4fc254f9a52727/src/pages/challenges/[slug].jsx#L1-L0

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
src/pages/challenges/[slug].jsx Add a check after the challenge data is fetched. If the data is not found (i.e., the challenge ID is invalid), redirect to a 404 page.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working on executing my plan and coding the required changes to address this issue. Here is the planned pull request:

Handle Invalid Challenge IDs sweep/issue-65-handle-invalid-challenge-ids

This PR addresses issue #65.

Previously, entering an invalid challenge ID in the URL would still return the challenge page, but with empty content. This PR changes this behavior to redirect to a 404 page instead.

Changes:

  • Added a check in src/pages/challenges/[slug].jsx to verify if the challenge data is fetched successfully. If not (i.e., the challenge ID is invalid), it redirects to a 404 page.

This ensures a better user experience as users are properly informed when they navigate to a non-existent challenge page.

Please review and let me know if there are any concerns.


Step 4: ⌨️ Coding

I have finished coding the issue. I am now reviewing it for completeness.


Step 5: 🔁 Code Review

Success! 🚀


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind! Join Our Discord