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

HIDEs the network key in the logs #1086

Merged
merged 5 commits into from
Jun 13, 2024
Merged

Conversation

ghoz
Copy link
Contributor

@ghoz ghoz commented Jun 9, 2024

We do it when calling Zigbee-herdsman from zigbee2mqtt, but not when receiving the config.

This has security implications and might require a communication as any user who shared their logs
also shared their network secret

We do in when calling Zigbee-herdsman from zigbee2mqtt, but not here
logger.debug(`Starting with options '${JSON.stringify(this.options)}'`, NS);

let optionsLog = objectAssignDeep({}, this.options, {network: {networkKey: 'HIDDEN'}});
logger.debug(`Starting with options '${JSON.stringify(optionsLog)}'`, NS);
Copy link
Owner

Choose a reason for hiding this comment

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

To prevent adding a new dependency, can we just do this here?

Suggested change
logger.debug(`Starting with options '${JSON.stringify(optionsLog)}'`, NS);
logger.debug(`Starting with options '${JSON.stringify(this.options).replace(this.options.network.networkKey, 'HIDDEN')}'`, NS);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably best to do that here too, instead of messing with objects.

Copy link
Collaborator

@Nerivec Nerivec Jun 11, 2024

Choose a reason for hiding this comment

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

Note: Probably this would be better as a feature of nurikk/zigbee2mqtt-frontend#2011 "Download sanitized". It could go through security (network key, IEEE...) and privacy (friendly names...) checks, on an existing file, specifically for sharing. That way local logs could retain all values for local debugging.

Copy link
Owner

Choose a reason for hiding this comment

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

But that doesn't apply to the log files in the log directory, I think it's good to keep it hidden in the logs as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It all comes down to the security of the machine in question, and the handling of the logs/config/backup (kept local vs shared/uploaded), since everything is kept in plain in the same folder.

If frontend provides a button to download any log (current or archived) with the sanitization logic applied when downloaded, it can provide any log "ready for sharing". With the option of manually accessing the files (directly), to see the plain versions.

Copy link
Contributor Author

@ghoz ghoz Jun 12, 2024

Choose a reason for hiding this comment

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

Logs are usually in a less safe place than the config, we definitively need to hide the secrets there...
Of course it does not preclude from having an option to download a sanitized version with anonymization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably best to do that here too, instead of messing with objects.

That's the line I used, for consistency indeed ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To prevent adding a new dependency, can we just do this here?

I was worried with networkKey as an array, but it seems to work. I'm JSON.stringify() it rather than toString() just in case and array.toString and JSON stringify don't behave the same for some reason.
One other thing I used replaceAll so that it wouldn't miss if you set your networkKey to an existing key for some weird reason... and instead make for a fun "guess the HIDDEN key" game.
So yeah it is technically more fragile and could still leak those type of weird keys

ghoz added 3 commits June 12, 2024 19:39
slightly more fragile, please don't use a networkKey  "network" or any other option key name...
stupid tabs
package.json Outdated
@@ -34,6 +34,7 @@
"fast-deep-equal": "^3.1.3",
"mixin-deep": "^2.0.1",
"mz": "^2.7.0",
"object-assign-deep": "^0.4.0",
Copy link
Owner

Choose a reason for hiding this comment

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

Could you remove the added dependencies here? After that this can be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to git add ...
Done

Koenkk added a commit to Koenkk/zigbee2mqtt that referenced this pull request Jun 13, 2024
@Koenkk Koenkk merged commit d06d9c5 into Koenkk:master Jun 13, 2024
1 check passed
@Koenkk
Copy link
Owner

Koenkk commented Jun 13, 2024

Thanks!

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.

3 participants