-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: current-cycle-hash resp type issue #35
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05b4d75
baked in newPOQReceipt = false
afostr e4e0405
3.4.20
afostr a270ead
Added the before/after account hash exist check in the appliedReceipt
jairajdev b5333f9
Additional hardening for old POQ
jairajdev 00e6712
fix: current-cycle-hash resp type issue
tanuj-shardeum 13cfc2e
3.4.21
afostr 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@shardus/archiver", | ||
"version": "3.4.19", | ||
"version": "3.4.20", | ||
"engines": { | ||
"node": "18.16.1" | ||
}, | ||
|
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,15 @@ export const verifyAccountHash = (receipt: ArchiverReceipt): boolean => { | |
) | ||
return false | ||
} | ||
if ( | ||
receipt.appliedReceipt.appliedVote.account_state_hash_before.length !== | ||
receipt.appliedReceipt.appliedVote.account_state_hash_after.length | ||
) { | ||
Logger.mainLogger.error( | ||
`Account state hash before and after count does not match! ${receipt.tx.txId} , ${receipt.cycle} , ${receipt.tx.timestamp}` | ||
) | ||
return false | ||
} | ||
for (const account of receipt.accounts) { | ||
if (account.data.accountType === AccountType.Account) { | ||
fixAccountUint8Arrays(account.data.account) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,16 @@ export const verifyAppReceiptData = async ( | |
appliedReceipt.appliedVote.account_state_hash_after.length > 0 | ||
) { | ||
for (let i = 0; i < appliedReceipt.appliedVote.account_id.length; i++) { | ||
if ( | ||
// eslint-disable-next-line security/detect-object-injection | ||
!appliedReceipt.appliedVote.account_state_hash_before[i] || | ||
// eslint-disable-next-line security/detect-object-injection | ||
!appliedReceipt.appliedVote.account_state_hash_after[i] | ||
) { | ||
Logger.mainLogger.error( | ||
`The account state hash before or after is missing in the receipt! ${receipt.tx.txId} , ${receipt.cycle} , ${receipt.tx.timestamp}` | ||
) | ||
} | ||
if ( | ||
// eslint-disable-next-line security/detect-object-injection | ||
appliedReceipt.appliedVote.account_state_hash_before[i] !== | ||
|
@@ -44,6 +54,7 @@ export const verifyAppReceiptData = async ( | |
// If the existing receipt is challenged and the new receipt is confirmed, overwrite the existing receipt | ||
let skipAppReceiptCheck = false | ||
if ( | ||
config.newPOQReceipt === true && | ||
existingReceipt.appliedReceipt && | ||
existingReceipt.appliedReceipt.confirmOrChallenge && | ||
receipt.appliedReceipt && | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,11 +192,11 @@ function syncLatestCycleRecordAndMarker( | |
activeNodes: P2PTypes.SyncTypes.ActiveNode[] | ||
): ResultAsync<[P2PTypes.CycleCreatorTypes.CycleData, hexstring], Error> { | ||
// run a robust query for the latest cycle record hash | ||
return robustQueryForCycleRecordHash(activeNodes).andThen(({ value: cycleRecordHash, winningNodes }) => | ||
return robustQueryForCycleRecordHash(activeNodes).andThen(({ value, winningNodes }) => | ||
// get current cycle record from node | ||
getCurrentCycleDataFromNode(winningNodes[0], cycleRecordHash).andThen((cycleRecord) => | ||
verifyCycleRecord(cycleRecord, cycleRecordHash).map( | ||
() => [cycleRecord, cycleRecordHash] as [P2PTypes.CycleCreatorTypes.CycleData, hexstring] | ||
getCurrentCycleDataFromNode(winningNodes[0], value.currentCycleHash).andThen((cycleRecord) => | ||
verifyCycleRecord(cycleRecord, value.currentCycleHash).map( | ||
() => [cycleRecord, value.currentCycleHash] as [P2PTypes.CycleCreatorTypes.CycleData, hexstring] | ||
) | ||
) | ||
) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ function attemptSimpleFetch<T>( | |
} | ||
|
||
/** Executes a robust query to retrieve the cycle marker from the network. */ | ||
export function robustQueryForCycleRecordHash(nodes: ActiveNode[]): RobustQueryResultAsync<hexstring> { | ||
export function robustQueryForCycleRecordHash(nodes: ActiveNode[]): RobustQueryResultAsync<{ currentCycleHash: hexstring }> { | ||
return makeRobustQueryCall(nodes, 'current-cycle-hash') | ||
} | ||
|
||
|
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Log injection Medium
Copilot Autofix AI 5 months ago
The problem with the code is that it logs user-provided data without sanitizing it first. This can lead to log injection attacks where an attacker can manipulate the log entries by providing malicious input.
To fix this issue, we need to sanitize the user-provided data before logging it. In this case, we can use the
String.prototype.replace
method to remove any newline characters from the user-provided data. This will prevent the attacker from creating new log entries by injecting newline characters into the input.In the file
src/API.ts
, we need to sanitize thegossipPayload
variable before passing it to theCollector.validateGossipData
andCollector.processGossipData
methods. We can do this by replacing all newline characters in thegossipPayload
string with an empty string.In the file
src/Data/Collector.ts
, we need to sanitize thegetCurrentCycleCounter()
function call before logging it. We can do this by converting the result of the function call to a string and then replacing all newline characters with an empty string.