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

Save only valid D-Bus Names #454

Open
wants to merge 1 commit into
base: master
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
7 changes: 6 additions & 1 deletion src/models/sessionBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ const {GObject} = imports.gi;
const {FlatpakSharedModel} = imports.models.shared;
const {FlatsealOverrideStatus} = imports.models.overrideStatus;

/* https://dbus.freedesktop.org/doc/dbus-specification.html */
const EXP = /^(([A-Z]|[a-z]|[0-9]|_|-)+)(\.(([A-Z]|[a-z]|[0-9]|_|-)+))+(\.\*){0,1}$/;

Choose a reason for hiding this comment

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

  • hyphens are not allowed
  • regex can be simplified (([A-Z]|[a-z]) -> ([A-Za-z]))
  • names must not start with an digit
Suggested change
const EXP = /^(([A-Z]|[a-z]|[0-9]|_|-)+)(\.(([A-Z]|[a-z]|[0-9]|_|-)+))+(\.\*){0,1}$/;
const EXP = /^([A-Za-z_][A-Za-z0-9_]+)(\.[A-Za-z_][A-Za-z0-9_]+)+(\.\*)?$/;

(untested suggestion)

Copy link
Author

Choose a reason for hiding this comment

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

This RegEx is not from me. It is already used in Flatseal.

/* https://dbus.freedesktop.org/doc/dbus-specification.html */
const EXP = /^(([A-Z]|[a-z]|[0-9]|_|-)+)(\.(([A-Z]|[a-z]|[0-9]|_|-)+))+(\.\*){0,1}$/;

It is used to display the valid icon in the D-Bus edit field. If it is wrong, it should be fixed in both places.

Copy link
Contributor

Choose a reason for hiding this comment

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

hypens are allowed, but just on the last segment of the name

Copy link
Owner

Choose a reason for hiding this comment

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

To make this better than I currently do it, how about we officially move the definition of this esoteric regexp to this model (e.g. var BUS_NAME_REGEX = ...), and then we import this constant here https://github.com/tchx84/Flatseal/blob/master/src/widgets/busNameRow.js#L28 (instead of duplicating it)


var FlatpakSessionBusModel = GObject.registerClass({
GTypeName: 'FlatpakSessionBusModel',
}, class FlatpakSessionBusModel extends FlatpakSharedModel {
_init() {
super._init({});
this._expression = new RegExp(EXP);
}

getPermissions() {
Expand Down Expand Up @@ -180,7 +183,9 @@ var FlatpakSessionBusModel = GObject.registerClass({
saveToKeyFile(keyFile) {
const group = this.constructor.getGroup();
Object.entries(this._overrides).forEach(([key, value]) => {
keyFile.set_value(group, key, value);
if (this._expression.test(key)) {
Copy link
Owner

Choose a reason for hiding this comment

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

For consistency, instead of doing this here, can you move this to updateFromProxyProperty? Like I do it here https://github.com/tchx84/Flatseal/blob/master/src/models/variables.js#L86

keyFile.set_value(group, key, value);
}
});
}

Expand Down