Skip to content

Solution#361

Open
dmdamyan wants to merge 2 commits intomate-academy:masterfrom
dmdamyan:develop
Open

Solution#361
dmdamyan wants to merge 2 commits intomate-academy:masterfrom
dmdamyan:develop

Conversation

@dmdamyan
Copy link
Copy Markdown

@dmdamyan dmdamyan commented Apr 2, 2026

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great work on setting up the static file server! The core logic for serving files from the public directory and handling 404 errors is correctly implemented.

However, changes are needed for two critical issues:

  1. Failing Security Test: The tests are failing because the server doesn't prevent path traversal. A request like /file/../somefile.js should be blocked with a 400 Bad Request status. You'll need to validate that the resolved file path stays within the public directory.
  2. Incorrect Root File Handling: According to the requirements, requests to /file and /file/ should serve the public/index.html file, but they currently return a text hint. Please adjust your logic to handle these specific cases.

Once these two issues are addressed, your solution will be complete. Keep up the great effort!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +87 to +92
if (pathname === '/file' || pathname === '/file/') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('To upload a file, use the path /file/<file_name>');

return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

According to the requirements, requests to /file and /file/ should return the public/index.html file. This implementation returns a hint message instead.

@dmdamyan
Copy link
Copy Markdown
Author

dmdamyan commented Apr 3, 2026

учёл замечание:
Некорректная обработка корневого файла : согласно требованиям, запросы к /fileфайлу /file/должны его обрабатывать public/index.html, но в настоящее время они возвращают текстовую подсказку. Пожалуйста, скорректируйте свою логику для обработки этих конкретных случаев.
по замечанию:
Проверка безопасности завершается неудачей : Тесты не проходят, потому что сервер не предотвращает обход пути. Запрос, подобный этому, /file/../somefile.jsдолжен быть заблокирован со 400 Bad Requestстатусом. Вам необходимо убедиться, что разрешенный путь к файлу остается в пределах publicкаталога.
проверка в коде есть, не знаю почему тест не проходит

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Review Summary

Great job addressing the previous feedback and correctly handling the root paths like /file and /file/. We're very close to a complete solution!

However, there are a couple of critical issues that need to be fixed.

  1. Path Traversal: The security check for path traversal is not working correctly, which is causing the tests to fail. A request like /file/../somefile.js must be blocked with a 400 Bad Request status. You can fix this by adding a check to see if the requested path contains .. before trying to serve the file.
  2. Incorrect Content-Type: When serving index.html for the root paths, the Content-Type is hardcoded as text/plain. This causes the browser to show the HTML code instead of rendering the page. Please use your getContentType helper function to set the correct type, which should be text/html.

Once these two issues are resolved, your server should meet all the requirements. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

);
const newPath = path.join(pathTopublicDir, 'index.html');

readFile(newPath, res, 'text/plain');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The content type for index.html is hardcoded to text/plain. This will cause the browser to display the HTML source code instead of rendering the page. You should use the correct MIME type, which you can get by using your getContentType helper function or by specifying 'text/html' directly.

@dmdamyan
Copy link
Copy Markdown
Author

dmdamyan commented Apr 3, 2026

Чтобы проверить работы теста, проверяющего наличие '..' в адресной строке, прописываю в адресе путь /file/../app.js и браузер её сразу же нормализует сам и в консоль выводится путь без '..'. Возможно из-за этого тест и не отлавливает эту ошибку. В тесте, где проверяется возврат index.html при /file и /file/, тест показывает:
Expected: "text/plain"
Received: "text/html; charset=utf-8"
т.е. функция смотрит на расширение файла и подставляет "text/html; charset=utf-8", а тест ожидает "text/plain". Я для прохождения этого теста убирал функцию и напрямую прописывал "text/plain", тест проходит, но ИИ не принимает,

Copy link
Copy Markdown

@Anton-Kuchmasov Anton-Kuchmasov left a comment

Choose a reason for hiding this comment

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

Great job you did!

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