Skip to content

Commit 8f02830

Browse files
authored
Merge pull request #9477 from ManageIQ/revert-9367-fix_searchbar_security_issue
Revert "Fix searchbar formtoken issue"
2 parents 4855914 + 24b06f6 commit 8f02830

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/javascript/components/search-bar/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
} from '@carbon/icons-react';
1010

1111
const SearchBar = ({ searchText, advancedSearch, action }) => {
12+
const formToken = () => {
13+
const csrfToken = document.querySelector('meta[name=csrf-token]');
14+
return csrfToken ? csrfToken.getAttribute('content') : '';
15+
};
1216
const [data, setData] = useState({
1317
formText: searchText || '',
1418
loading: false,
@@ -92,7 +96,7 @@ const SearchBar = ({ searchText, advancedSearch, action }) => {
9296
return (
9397
<div className="search_bar">
9498
<Form onSubmit={onSearch} method="post" id="search-bar-form">
95-
<input type="hidden" name="authenticity_token" />
99+
<input type="hidden" name="authenticity_token" value={formToken()} />
96100
<TextInput
97101
id="search_text"
98102
labelText={__('Search')}

app/javascript/spec/search-bar/__snapshots__/search-bar.spec.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`Search Bar component should render the search bar component 1`] = `
1212
<input
1313
name="authenticity_token"
1414
type="hidden"
15+
value=""
1516
/>
1617
<TextInput
1718
hideLabel={true}
@@ -72,6 +73,7 @@ exports[`Search Bar component should render the search bar component with advanc
7273
<input
7374
name="authenticity_token"
7475
type="hidden"
76+
value=""
7577
/>
7678
<TextInput
7779
hideLabel={true}
@@ -132,6 +134,7 @@ exports[`Search Bar component should render the search bar component with search
132134
<input
133135
name="authenticity_token"
134136
type="hidden"
137+
value=""
135138
/>
136139
<TextInput
137140
hideLabel={true}

0 commit comments

Comments
 (0)