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

MWPW-144360 Prototype pollution tag selector #2967

Open
wants to merge 1 commit into
base: stage
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions libs/blocks/tag-selector/tag-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import Picker from '../../ui/controls/TagSelectPicker.js';
import { loadCaasTags } from '../caas/utils.js';

const CAAS_LABEL = 'CaaS';
const TAG_KEYS = ['Type', 'Name'];

async function fetchData(url) {
async function fetchTags(url) {
const resp = await fetch(url.toLowerCase());

if (!resp.ok) throw new Error('Network error');

const json = await resp.json();
return json;
const { data } = await resp.json();

if (!Array.isArray(data)) throw new Error('Could not parse data');

return data.map((item) => {
const tag = Object.create(null);
TAG_KEYS.forEach((key) => { tag[key] = item[key]; });

return tag;
});
}

const TagPreview = ({ selectedTags = [] }) => {
Expand Down Expand Up @@ -93,9 +102,12 @@ const TagSelector = ({ consumerUrls = [] }) => {

const fetchConsumer = () => {
consumerUrls.forEach(({ title, url }) => {
fetchData(url).then((json) => {
const tags = getConsumerTags(json.data);
fetchTags(url).then((data) => {
const tags = getConsumerTags(data);
setTagSelectorTags((prevConsumerTags) => ({ [title]: tags, ...prevConsumerTags }));
}).catch((e) => {
/* c8 ignore next 2 */
window.lana.log(`Tag Selector. Error fetching consumer tags: ${e.message}`, { tags: 'tag-selector', errorType: 'i' });
});
});
};
Expand Down
Loading