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

Validate dataURL to prevent XSS attacks #4057

Closed
gtsp233 opened this issue Jan 20, 2024 · 0 comments · Fixed by #4065
Closed

Validate dataURL to prevent XSS attacks #4057

gtsp233 opened this issue Jan 20, 2024 · 0 comments · Fixed by #4065
Labels

Comments

@gtsp233
Copy link

gtsp233 commented Jan 20, 2024

Hi, I've found a Cross-Site Scripting (XSS) vulnerability in @rjsf/core

Vulnerability Details:

  • Severity: High/Critical
  • Description: There's a risk of malicious script execution when the value of the FileWidget is controlled by an adversary.

Steps to Reproduce:

import React from "react";
import ReactDOM from "react-dom/client";
import { getDefaultRegistry } from "@rjsf/core";

const schema = {
  title: "Files",
  type: "object",
  properties: {
    file: {
      type: "string",
      format: "data-url",
      title: "Single file",
    },
  },
};

function App() {
  const FileWidget = getDefaultRegistry().widgets.FileWidget;

  return (
    <FileWidget
      value={["javascript:alert(1)"]}
      registry={getDefaultRegistry()}
      options={{ id: 1, filePreview: true }}
      id="1"
      schema={schema}
      onChange={() => {}}
      onFocus={() => {}}
    />
  );
}

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);

In this case, when a user clicks the preview button, the malicious script alert(1) will be executed. Note that the specified format: "data-url" does not successfully sanitize the value.

Suggested Fix or Mitigation:
The root cause is due to:

<a download={`preview-${name}`} href={dataURL} className='file-download'>

where a malicious dataURL may be passed to the <a />, causing an XSS attack.

It is best practice for a package to ensure security. Even though the dataURL has been validated elsewhere, there's still a risk of malicious dataURL being passed to <a /> as shown in the example. Please consider patching this issue by validating the dataURL to prevent the XSS attack. Thanks!

@github-actions github-actions bot added the needs triage Initial label given, to be assigned correct labels and assigned label Jan 20, 2024
@heath-freenome heath-freenome added bug and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants