Skip to content

✨ feat: add guestbook feature with routes and view - #21

Open
azigler wants to merge 1 commit into
base-jsfrom
add-guestbook-routes-qodo
Open

azigler wants to merge 1 commit into
base-jsfrom
add-guestbook-routes-qodo

Conversation

@azigler

@azigler azigler commented Jun 30, 2025

Copy link
Copy Markdown
Contributor

PR Type

Enhancement


Description

  • Add guestbook feature with GET/POST routes

  • Create guestbook controller with in-memory storage

  • Implement Pug template for guestbook interface

  • Enable users to view and submit messages


Changes diagram

flowchart LR
  A["User Request"] --> B["Guestbook Routes"]
  B --> C["Guestbook Controller"]
  C --> D["In-Memory Storage"]
  C --> E["Pug Template"]
  E --> F["Rendered View"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
app.js
Register guestbook routes and controller                                 

app.js

  • Import guestbook controller module
  • Add GET and POST routes for /guestbook endpoint
  • +7/-0     
    guestbook.js
    Create guestbook controller with CRUD operations                 

    controllers/guestbook.js

  • Create controller with in-memory entries array
  • Implement GET handler to render guestbook view
  • Implement POST handler to add entries and redirect
  • +10/-0   
    guestbook.pug
    Create guestbook view template                                                     

    views/guestbook.pug

  • Create Pug template extending base layout
  • Add form for message submission
  • Display existing entries in unordered list
  • +11/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @coderabbitai

    coderabbitai Bot commented Jun 30, 2025

    Copy link
    Copy Markdown

    Important

    Review skipped

    Auto reviews are disabled on base/target branches other than the default branch.

    Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

    You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


    🪧 Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>, please review it.
      • Explain this complex logic.
      • Open a follow-up GitHub issue for this discussion.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai explain this code block.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
      • @coderabbitai read src/utils.ts and explain its main purpose.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
      • @coderabbitai help me debug CodeRabbit configuration file.

    Support

    Need help? Create a ticket on our support page for assistance with any issues or questions.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (Invoked using PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai full review to do a full review from scratch and review all the files again.
    • @coderabbitai summary to regenerate the summary of the PR.
    • @coderabbitai generate docstrings to generate docstrings for this PR.
    • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
    • @coderabbitai help to get help.

    Other keywords and placeholders

    • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
    • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
    • Add @coderabbitai anywhere in the PR title to generate the title automatically.

    CodeRabbit Configuration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • Please see the configuration documentation for more information.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

    Documentation and Community

    • Visit our Documentation for detailed information on how to use CodeRabbit.
    • Join our Discord Community to get help, request features, and share feedback.
    • Follow us on X/Twitter for updates and announcements.

    @azigler

    azigler commented Jun 30, 2025

    Copy link
    Copy Markdown
    Contributor Author

    /review

    @qodo-code-review

    qodo-code-review Bot commented Jun 30, 2025

    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    (Review updated until commit f6156b9)

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 Security concerns

    XSS vulnerability:
    The guestbook feature has a critical XSS vulnerability. In views/guestbook.pug line 11, li!= entry.message uses unescaped HTML rendering, allowing users to inject malicious JavaScript that will execute in other users' browsers. Additionally, the controller doesn't validate or sanitize the req.body.message input before storing it. This could allow attackers to inject <script> tags or other malicious HTML/JavaScript code that would be executed when other users view the guestbook.

    ⚡ Recommended focus areas for review

    Security Vulnerability

    The entries array is stored in memory without any validation or sanitization of user input, and the template renders messages with unescaped HTML which could lead to XSS attacks.

    let entries = [];
    
    exports.getGuestbook = (req, res) => {
      res.render('guestbook', { entries });
    };
    
    exports.postGuestbook = (req, res) => {
      entries.push({ message: req.body.message });
      res.redirect('/guestbook');
    }; 
    XSS Risk

    Using unescaped HTML rendering for user messages creates a direct XSS vulnerability where malicious scripts can be executed in other users' browsers.

    li!= entry.message 
    Data Persistence

    In-memory storage means all guestbook entries will be lost when the server restarts, which may not be the intended behavior for a guestbook feature.

    let entries = [];

    @qodo-code-review

    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Security
    Fix XSS vulnerability

    Using != for unescaped output creates an XSS vulnerability as user input is
    rendered directly without sanitization. Use = instead to escape HTML content
    safely.

    views/guestbook.pug [11]

    -li!= entry.message
    +li= entry.message
    • Apply / Chat
    Suggestion importance[1-10]: 10

    __

    Why: This suggestion correctly identifies and fixes a critical Cross-Site Scripting (XSS) security vulnerability by changing unescaped output != to escaped output =.

    High
    General
    Add input validation check

    Add validation to check if req.body.message exists and is not empty before
    pushing to entries. This prevents adding undefined or empty entries to the
    guestbook.

    controllers/guestbook.js [7-10]

     exports.postGuestbook = (req, res) => {
    -  entries.push({ message: req.body.message });
    +  if (req.body.message && req.body.message.trim()) {
    +    entries.push({ message: req.body.message });
    +  }
       res.redirect('/guestbook');
     };
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly points out the lack of server-side validation, which is good practice even with client-side validation (required attribute in the view), improving the application's robustness.

    Low
    • More

    Comment thread views/guestbook.pug
    button(type="submit") Sign Guestbook
    ul
    each entry in entries
    li!= entry.message No newline at end of file

    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 != operator in Pug renders unescaped HTML, which creates a cross-site scripting (XSS) vulnerability. An attacker could submit a message containing malicious script tags that would execute when viewed by other users.

    For security, please use the = operator instead:

    li= entry.message

    This ensures all HTML special characters are properly escaped before rendering.

    Suggested change
    li!= entry.message
    li= entry.message

    Spotted by Diamond

    Is this helpful? React 👍 or 👎 to let us know.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant