Skip to content

Addressing CORS Vulnerability for OnTrack Application (Documentation)#23

Merged
aNebula merged 2 commits into
thoth-tech:mainfrom
epineto:owasp10/cors-security-patch-fix-documentation
Dec 21, 2024
Merged

Addressing CORS Vulnerability for OnTrack Application (Documentation)#23
aNebula merged 2 commits into
thoth-tech:mainfrom
epineto:owasp10/cors-security-patch-fix-documentation

Conversation

@epineto
Copy link
Copy Markdown
Contributor

@epineto epineto commented Dec 10, 2024

Title: "Remediation: Addressing CORS Vulnerability for OnTrack Application"


Summary:
This PR addresses a Cross-Origin Resource Sharing (CORS) vulnerability in the OnTrack application caused by the use of the Access-Control-Allow-Origin: * header. The current configuration poses significant security risks by allowing unrestricted cross-origin access.


Impacts:

  • Unauthorized Access:
    Any website can interact with the API, potentially leading to data leakage or abuse.
  • Increased Attack Surface:
    Vulnerable to cross-origin attacks and other malicious activities.
  • Compliance Risks:
    Violates security and privacy standards.

Remediation:

  • Preferred Option: Restrict Access-Control-Allow-Origin:
    • Implement a restrictive CORS policy using the DF_ALLOWED_ORIGINS environment variable for flexibility.
    • Update backend configurations in:
      • Docker: /doubtfire-api/docker-compose.yml
      • Rails: /doubtfire-api/config/application.rb

Configuration Updates:

  1. Docker:

    • Add the following environment variable:
      DF_ALLOWED_ORIGINS: "http://localhost:4200,https://example.com"
    • Notes:
      • The DF_ALLOWED_ORIGINS variable must reflect the exact URLs where the OnTrack app will be accessed (e.g., production, staging, or development environments).
      • Failure to update this variable correctly will result in inaccessibility for valid clients.
  2. Rails:

    • Add middleware configuration in application.rb:
      config.middleware.insert_before Warden::Manager, Rack::Cors do
        allow do
          origins ENV['DF_ALLOWED_ORIGINS'].split(',')
          resource '*', headers: :any, methods: %i[get post put delete options]
        end
      end

Testing Plan:

  1. Functional Testing:
    • Validate that access is successful for allowed origins (e.g., http://localhost:4200).
    • Confirm that access is blocked for unauthorized domains.
  2. Security Testing:
    • Use Postman to simulate requests with custom Origin headers.
  3. Regression Testing:
    • Verify that all endpoints remain functional after the changes.

Postman Validation Steps:

  1. Create a new request in Postman.
  2. Set the method (e.g., GET, POST) and endpoint.
  3. Add a header:
    • Key: Origin
    • Value: http://localhost:4200
  4. Observe the response to confirm behavior for allowed and unauthorized domains.
  5. Save and exit the file.

Expected Outcome:

  • The application restricts cross-origin access to only the specified origins in DF_ALLOWED_ORIGINS.
  • Compliance with security and privacy standards is improved, reducing the risk of unauthorized access and cross-origin attacks.

Reviewer Notes:

  • Ensure that the changes in Docker and Rails configurations align with the production, staging, and development requirements.
  • Verify that the DF_ALLOWED_ORIGINS environment variable is updated appropriately in all environments before deployment.
  • Validate the behavior in local and staging environments before pushing to production.

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 10, 2024

Deploy Preview for ontrackdocumentation ready!

Name Link
🔨 Latest commit d1d2758
🔍 Latest deploy log https://app.netlify.com/sites/ontrackdocumentation/deploys/6757b05bcb65480008116ccc
😎 Deploy Preview https://deploy-preview-23--ontrackdocumentation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@washyking
Copy link
Copy Markdown

This is a good PR it addresses the CORS security risk. I tested below using postman and it was successfully blocked. . See below

Sent from correct orign

Screenshot 2024-12-11 at 12 12 27 pm

Sent from bad origin

Screenshot 2024-12-11 at 12 12 53 pm

Good work.

@epineto
Copy link
Copy Markdown
Contributor Author

epineto commented Dec 12, 2024

@washyking , could you please review this PR? Thanks a lot!

Copy link
Copy Markdown

@nodogx nodogx left a comment

Choose a reason for hiding this comment

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

This pull request documentation addresses the CORS vulnerability. This is done by implementing a flexible and restrictive CORS using the DF_ALLOWED_ORIGINS env variable which makes sure security while managing the configurability. I have also tried the CORS to ensure if this works, which does

The code logic looks really good. I have tried to get the CORS headers as well for an unauthorised website, which it doesn't give. Which shows it works as intended :)

Unauthorised Website

Screenshot 2024-12-13 at 12 37 35 am

Authorised Website

Headers:

Screenshot 2024-12-13 at 12 36 02 am

@aNebula aNebula self-requested a review December 21, 2024 04:58
@aNebula aNebula requested review from aNebula and removed request for aNebula December 21, 2024 04:58
@aNebula aNebula merged commit 01f9633 into thoth-tech:main Dec 21, 2024
Roeenk27 pushed a commit to Roeenk27/doubtfire-astro that referenced this pull request Mar 17, 2026
fix: force npm install in the vscode task
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.

5 participants