-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sanitize javascript: urls for <object> tags
React 19 added sanitization for `javascript:` URLs for `href` properties on various tags. This PR also adds that sanitization for `<object>` tags as well that Firefox otherwise executes.
- Loading branch information
Showing
4 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/react-dom/src/__tests__/ReactDOMServerIntegrationObject-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @jest-environment ./scripts/jest/ReactDOMServerIntegrationEnvironment | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); | ||
|
||
let React; | ||
let ReactDOMClient; | ||
let ReactDOMServer; | ||
|
||
function initModules() { | ||
// Reset warning cache. | ||
jest.resetModules(); | ||
React = require('react'); | ||
ReactDOMClient = require('react-dom/client'); | ||
ReactDOMServer = require('react-dom/server'); | ||
|
||
// Make them available to the helpers. | ||
return { | ||
ReactDOMClient, | ||
ReactDOMServer, | ||
}; | ||
} | ||
|
||
const {resetModules, itRenders} = ReactDOMServerIntegrationUtils(initModules); | ||
|
||
describe('ReactDOMServerIntegrationObject', () => { | ||
beforeEach(() => { | ||
resetModules(); | ||
}); | ||
|
||
itRenders('an object with children', async render => { | ||
const e = await render( | ||
<object type="video/mp4" data="/example.webm" width={600} height={400}> | ||
<div>preview</div> | ||
</object>, | ||
); | ||
|
||
expect(e.outerHTML).toBe( | ||
'<object type="video/mp4" data="/example.webm" width="600" height="400"><div>preview</div></object>', | ||
); | ||
}); | ||
|
||
itRenders('an object with empty data', async render => { | ||
const e = await render(<object data="" />, 1); | ||
expect(e.outerHTML).toBe('<object></object>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters