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

Website: Clean Air Forum 2025 #2437

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Website: Clean Air Forum 2025 #2437

merged 1 commit into from
Feb 4, 2025

Conversation

OchiengPaul442
Copy link
Contributor

@OchiengPaul442 OchiengPaul442 commented Feb 4, 2025

Summary of Changes (What does this PR do?)

  • Fix on the About section where Objective content is not displayed well

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state

Screenshots (optional)

image

Summary by CodeRabbit

  • New Features
    • Introduced a reusable layout component that supports a consistent two-column design for key page sections.
  • Refactor
    • Streamlined the presentation of sponsorship and objectives sections by consolidating and updating their structure.
  • Style
    • Improved the semantic structure of the About page through cleaner headers and section separation for enhanced readability.

Copy link

coderabbitai bot commented Feb 4, 2025

📝 Walkthrough

Walkthrough

The pull request refactors the About page by introducing a new reusable component called SectionRow. This component facilitates a consistent two-column layout where a bold title is paired with corresponding content. The renderObjectives function now uses SectionRow to display each objective retrieved from data?.engagement?.objectives. Additionally, the introduction section is now wrapped in a semantic <section> element, and a debugging log (console.info(data);) has been added. The changes replace the former verbose nested div structure and inline styles with a cleaner, more modular approach.

Changes

File(s) Change Summary
website2/src/views/Forum/AboutPage.tsx Added new reusable SectionRow component and its props type. Updated renderObjectives to map over objectives using SectionRow. Refactored introduction and sponsorship sections from nested divs to semantic markup. Added a debugging log statement.

Sequence Diagram(s)

sequenceDiagram
    participant AP as AboutPage
    participant SR as SectionRow

    AP->>SR: Render Introduction Section (with header)
    SR-->>AP: Returns Introduction section

    AP->>SR: Render Sponsorship Opportunities Section
    SR-->>AP: Returns Sponsorship Opportunities section

    AP->>SR: Render Sponsorship Packages Section
    SR-->>AP: Returns Sponsorship Packages section
Loading
sequenceDiagram
    participant AP as AboutPage
    participant Data as Objectives Data
    participant SR as SectionRow

    AP->>Data: Retrieve objectives data (data?.engagement?.objectives)
    Data-->>AP: Return objectives list
    loop For each objective
        AP->>SR: Render objective with title & details
        SR-->>AP: Section rendered for objective
    end
Loading

Suggested reviewers

  • Baalmart
  • Codebmk

Poem

In the realm of code where structure's our art,
SectionRow emerges, playing its part.
Objectives align in a clean, smart display,
Debug logs whisper as design finds its way.
A tasteful refactor brightens the page—
Code dancing gracefully on a digital stage!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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 or @coderabbitai title 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
website2/src/views/Forum/AboutPage.tsx (3)

8-21: Nice work on the SectionRow component! 👍

The component is well-structured and provides a consistent layout pattern. The TypeScript types are properly defined.

Consider adding a className prop to allow more flexible styling when needed:

 type SectionRowProps = {
   title: string;
   children: React.ReactNode;
+  className?: string;
 };

-const SectionRow: React.FC<SectionRowProps> = ({ title, children }) => (
+const SectionRow: React.FC<SectionRowProps> = ({ title, children, className = '' }) => (
-  <div className="py-4 flex flex-col md:flex-row items-start transition duration-150 ease-in-out hover:bg-gray-50 rounded">
+  <div className={`py-4 flex flex-col md:flex-row items-start transition duration-150 ease-in-out hover:bg-gray-50 rounded ${className}`}>

30-30: Remove debug console.log

The console.info statement appears to be for debugging purposes and should be removed before production deployment.

-  console.info(data);

34-34: Add null coalescing for safer optional chaining

The optional chaining could be combined with null coalescing for more robust fallbacks.

-  const objectives = data?.engagement?.objectives || [];
+  const objectives = data?.engagement?.objectives ?? [];

-  data?.sponsorship_opportunities_about || '',
+  data?.sponsorship_opportunities_about ?? '',

-  data?.sponsorship_packages || '',
+  data?.sponsorship_packages ?? '',

Also applies to: 76-76, 88-88

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1cde9d and 990d0c1.

📒 Files selected for processing (1)
  • website2/src/views/Forum/AboutPage.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
website2/src/views/Forum/AboutPage.tsx

[error] 60-60: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)


[error] 74-74: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)


[error] 87-87: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-push-website2-deploy-preview

Comment on lines +33 to +47
const renderObjectives = () => {
const objectives = data?.engagement?.objectives || [];
return (
<section className="space-y-6">
<h2 className="text-2xl font-bold text-left">Objectives</h2>
<div className="divide-y divide-gray-200">
{objectives.map((objective: any) => (
<SectionRow key={objective.id} title={objective.title}>
{objective.details}
</SectionRow>
))}
</div>
</section>
);
};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Type safety improvements needed in objectives mapping

The use of any type in the objectives mapping could lead to runtime errors. Let's properly type this for better type safety.

+ type Objective = {
+   id: string | number;
+   title: string;
+   details: string;
+ };

  const renderObjectives = () => {
-   const objectives = data?.engagement?.objectives || [];
+   const objectives: Objective[] = data?.engagement?.objectives || [];
    return (
      <section className="space-y-6">
        <h2 className="text-2xl font-bold text-left">Objectives</h2>
        <div className="divide-y divide-gray-200">
-         {objectives.map((objective: any) => (
+         {objectives.map((objective: Objective) => (
            <SectionRow key={objective.id} title={objective.title}>
              {objective.details}
            </SectionRow>
          ))}
        </div>
      </section>
    );
  };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const renderObjectives = () => {
const objectives = data?.engagement?.objectives || [];
return (
<section className="space-y-6">
<h2 className="text-2xl font-bold text-left">Objectives</h2>
<div className="divide-y divide-gray-200">
{objectives.map((objective: any) => (
<SectionRow key={objective.id} title={objective.title}>
{objective.details}
</SectionRow>
))}
</div>
</section>
);
};
type Objective = {
id: string | number;
title: string;
details: string;
};
const renderObjectives = () => {
const objectives: Objective[] = data?.engagement?.objectives || [];
return (
<section className="space-y-6">
<h2 className="text-2xl font-bold text-left">Objectives</h2>
<div className="divide-y divide-gray-200">
{objectives.map((objective: Objective) => (
<SectionRow key={objective.id} title={objective.title}>
{objective.details}
</SectionRow>
))}
</div>
</section>
);
};

Comment on lines +60 to +62
dangerouslySetInnerHTML={{
__html: renderContent(data.introduction),
}}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Security Concern: Insufficient Sanitization in renderContent

Based on our investigation:

  • The renderContent function in website2 appears in two locations:
    • ./website2/src/components/ui/MemberCard.tsx
    • ./website2/src/utils/quillUtils.ts
  • Our search shows no evidence of a sanitization library (e.g., DOMPurify) being used within these functions. The only instance of DOMPurify in the repository is in the frontend code (i.e., ./website/frontend/src/pages/CleanAir/ForumEventsPages/Resources.js), not within the website2 implementation.
  • Without proper sanitization, any HTML processed by renderContent and rendered via dangerouslySetInnerHTML is at risk of XSS vulnerabilities.

Action Items:

  • Audit renderContent Implementation: Revisit the code in ./website2/src/utils/quillUtils.ts (and possibly MemberCard.tsx) to verify if any sanitization is performed.
  • Apply Proper Sanitization: If not already done, use a well-tested library like DOMPurify to sanitize HTML before rendering.
  • Review Other Usages: Ensure that all other instances of dangerouslySetInnerHTML (e.g., in AboutPage at lines 60-62, and similar sections at lines 74-78 and 87-89) are also receiving sanitized content.

Given the lack of evidence for sanitization in website2's implementation, this poses a potential security risk.

🔗 Analysis chain

Security: Review dangerouslySetInnerHTML usage

The use of dangerouslySetInnerHTML in multiple locations could expose users to XSS attacks if the content isn't properly sanitized.

Please verify that the renderContent utility function properly sanitizes HTML content. Consider using a well-tested HTML sanitization library like DOMPurify.

Also applies to: 74-78, 87-89


I'll start by gathering more information about how the renderContent utility function is implemented and whether it makes use of a sanitization library like DOMPurify. In particular, we need to confirm that any HTML handed to dangerouslySetInnerHTML is properly cleaned before rendering.

Below is a shell script to search the codebase for the definition of renderContent and to check for any references to DOMPurify:

Once we review the output of this script, we'll be able to confirm whether the HTML passed to dangerouslySetInnerHTML is being sanitized properly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Web query:

What are the best practices for safely rendering HTML content in React?

Length of output: 6741


Script:

#!/bin/bash
echo "Searching for 'renderContent' definition in the codebase..."
rg -n "function renderContent" .
rg -n "const renderContent" .

echo ""
echo "Searching for DOMPurify usage in the codebase..."
rg -n "DOMPurify" .

Length of output: 829

🧰 Tools
🪛 Biome (1.9.4)

[error] 60-60: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

Copy link
Contributor

github-actions bot commented Feb 4, 2025

New Website2 changes available for preview here

@Baalmart Baalmart merged commit 2ccd675 into staging Feb 4, 2025
31 checks passed
@Baalmart Baalmart deleted the website-update-codebase branch February 4, 2025 13:14
@Baalmart Baalmart mentioned this pull request Feb 4, 2025
2 tasks
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.

2 participants