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

ENH Avoid potential data disclosure #233

Merged

Conversation

GuySartorelli
Copy link
Member

Comment on lines -356 to +369
const type = types.hasOwnProperty(data[linkID]?.typeKey) ? types[data[linkID]?.typeKey] : {};
const type = types.hasOwnProperty(linkData.typeKey) ? types[linkData.typeKey] : {};
links.push(<LinkPickerTitle
key={linkID}
id={linkID}
title={data[linkID]?.Title}
description={data[linkID]?.description}
versionState={data[linkID]?.versionState}
title={linkData.title}
description={linkData.description}
versionState={linkData.versionState}
typeTitle={type.title || ''}
typeIcon={type.icon}
onDelete={handleDelete}
onClick={() => { setEditingID(linkID); }}
onButtonKeyDownEdit={() => setIsKeyboardEditing(true)}
onUnpublishedVersionedState={handleUnpublishedVersionedState}
canDelete={data[linkID]?.canDelete ? true : false}
canDelete={linkData.canDelete ? true : false}
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated refactoring - this variable is explicitly created above so a) let's use it and b) no need for null safety chaining operator.

$data = $link->jsonSerialize();
$data['canDelete'] = $link->canDelete();
$data['description'] = $link->getDescription();
$data['versionState'] = $link->getVersionedState();
return $data;
return $link->getData();
Copy link
Member Author

@GuySartorelli GuySartorelli Feb 19, 2024

Choose a reason for hiding this comment

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

Moved these into the method on Link since the only time the method is called is here. Makes it easier to maintain and see the full list of what's passed through to the react component from PHP in one place.

Comment on lines +215 to +219
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'canDelete' => $this->canDelete(),
'versionState' => $this->getVersionedState(),
'typeKey' => $typeKey,
Copy link
Member Author

Choose a reason for hiding this comment

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

Explicitly only these are used in the component.
Even creating super-duper unique link subclasses won't require adding more data here - the modal is handled separately, this is just for display before opening the modal.

There's no way to easily customise the react component, so adding an extension hook to update this data is overkill.

* Return a rendered version of this form.
* Return a rendered version of this link.
*
* This is returned when you access a form as $FormObject rather
* than <% with FormObject %>
* This is returned when you access a link as $LinkRelation or $Me rather
* than <% with LinkRelation %>
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated refactoring - a link is not a form, this was probably just copy pasted from elsewhere originally.

title={data[linkID]?.Title}
description={data[linkID]?.description}
versionState={data[linkID]?.versionState}
title={linkData.title}
Copy link
Member Author

@GuySartorelli GuySartorelli Feb 19, 2024

Choose a reason for hiding this comment

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

Note upper case Title is now lower case title - all of the data is now using lowerCamelCase key names, as per javascript tradition. It was a mix before.

@emteknetnz
Copy link
Member

Tested locally, works good

@emteknetnz emteknetnz merged commit 87e8c17 into silverstripe:4 Feb 20, 2024
12 checks passed
@emteknetnz emteknetnz deleted the pulls/4/refactor-jsonSerialize branch February 20, 2024 03:32
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.

2 participants