-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
prevent /upload from overwriting wsec.json #5482
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
Open
FoamyGuy
wants to merge
4
commits into
wled:main
Choose a base branch
from
FoamyGuy:restrict_upload_wsecjson
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make
denyWsecUploadsecure-by-default.Initializing this to
falsekeepswsec.jsonupload overwrite allowed until users manually enable it, so the protection is not enforced by default. Set default totrueand let users opt out if needed.🔒 Proposed change
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai i am not sure if
trueorfalseis the better default here. Please create an FMEA - feared event is "loss of security settings" and "bootloop/bricked device". Consider consequences for existing setups (upgrade path) and fresh setups. Also assess if storing the flag in cfg.json or in wsec.json makes a difference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@softhack007, here is the requested FMEA. The two feared top-level events are FE-1: Loss of security settings and FE-2: Bootloop/bricked device.FMEA:
denyWsecUploadDefault ValueFailure Mode Table
falsetrue_INITfalse→ upload re-enabled → recovery path existstrue→ upload still blocked → serial recovery requiredpwdCorrect#3#3, but cfg.json value may survive if cfg.json intactdeny-wseckey)_INITdefault used_INITdefault governs from first bootThe Critical Circular-Dependency Risk
Because
denyWsecUploadis stored insidewsec.json(per theserializeConfigSec/deserializeConfigSecchanges in this PR), the flag and the file it guards share the same fate:_INIT(true)directly worsens FE-2 (bricked device) in the scenario wherewsec.jsonis the corrupted file. This is particularly relevant because the very threat this PR is defending against (a malformed wsec.json upload) can leave the device in exactly that state.cfg.json vs wsec.json Storage — Does It Matter?
_INITgoverns./upload.pwdCorrect; wsec.json value loaded indeserializeConfigSec. If wsec.json is missing, cfg.json may still carry the value — but only on an authenticated session. On first boot after a partial wipe, the deserialization order determines which "wins".Storing the flag in cfg.json is safer for recovery because cfg.json can survive an independent wsec.json corruption. The current dual-storage in the PR is a reasonable middle ground, but it still leaves the circular-dependency risk for a full wipe.
Upgrade-Path Assessment
falsetrueRecommendation
Based on this FMEA,
_INIT(false)is the safer default primarily because:_INIT(true)turns a corrupted/deletedwsec.jsoninto a non-recoverable situation without serial access._INIT(false)preserves existing behaviour for all current installations; users who want the protection actively enable it.wsec.jsondoes not expose the previous secrets; it replaces them, so it is a valid recovery mechanism.The real defence against malformed-JSON bootloops should be input validation at load time (as softhack007 noted applies equally to
cfg.json), not upload blocking. ThedenyWsecUploadflag is still valuable as an optional hardening measure for installations that do not need the upload-recovery path, but should default tofalseand be documented as an advanced security option.🧠 Learnings used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@softhack007, glad the analysis was useful! I'll withdraw my original suggestion to flip the default totrue— the FMEA makes a clear case that_INIT(false)is the right choice here.Recording the rationale for future reviews:
✏️ Learnings added
🧠 Learnings used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai thanks, well done 🥇 . so we'll keep
falseas the default. PR #5484 takes care of hardening JSON file reading.