-
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
Conversation
BLUE-117 syncV2 is breaking in archiver due to 'current-cycle-hash'
ISSUE SUMMARY: The
I had to change the above code in the archiver archive-server/src/sync-v2/queries.ts Line 43 in 2790f66
<<TODO: Replace this with a short summary of the issue.>> ISSUE REPRO STEPS: <HINT: Add steps to list as-needed. If interaction is complex, add screenshots or a Slack screen-capture video (just drag and drop)>
EXPECTED RESULT: <<TODO: Replace this with your expected results.>> PULL REQUESTS: <HINT: If your fix requires changes in multiple repos, add the following info per-repository.> <<TODO: Enter Repository Name>> Pull Request Link: <<TODO: Insert PR-LINK>> GPT Review Link: <<TODO: Insert GPT-Review-Link>> Jenkins Test Link: <<TODO: Insert Jenkins Test Job Link>> ADDITIONAL INSTRUCTIONS: <HINT: Add any additional instructions needed for the assignee. If you have specific requirements for how the task should be implemented or fixed, enter them or link them here.> <<TODO: Insert additional instructions for assignee.>> |
) | ||
if (savedReceiptsCount > 0) | ||
Logger.mainLogger.debug( | ||
`Clean ${savedReceiptsCount} old receipts from the processed receipts cache on cycle ${getCurrentCycleCounter()}` |
Check warning
Code scanning / CodeQL
Log injection Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
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 the gossipPayload
variable before passing it to the Collector.validateGossipData
and Collector.processGossipData
methods. We can do this by replacing all newline characters in the gossipPayload
string with an empty string.
In the file src/Data/Collector.ts
, we need to sanitize the getCurrentCycleCounter()
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.
-
Copy modified lines R1255-R1257 -
Copy modified line R1259 -
Copy modified line R1261
@@ -1254,6 +1254,9 @@ | ||
} | ||
if (savedReceiptsCount > 0) | ||
if (savedReceiptsCount > 0) { | ||
// Sanitize getCurrentCycleCounter() by replacing newline characters | ||
const sanitizedCycleCounter = String(getCurrentCycleCounter()).replace(/\n|\r/g, "") | ||
Logger.mainLogger.debug( | ||
`Clean ${savedReceiptsCount} old receipts from the processed receipts cache on cycle ${getCurrentCycleCounter()}` | ||
`Clean ${savedReceiptsCount} old receipts from the processed receipts cache on cycle ${sanitizedCycleCounter}` | ||
) | ||
} | ||
} |
-
Copy modified lines R839-R841
@@ -838,3 +838,5 @@ | ||
server.post('/gossip-data', async (_request: GossipDataRequest, reply) => { | ||
const gossipPayload = _request.body | ||
let gossipPayload = _request.body | ||
// Sanitize gossipPayload by replacing newline characters | ||
gossipPayload = JSON.parse(JSON.stringify(gossipPayload).replace(/\\n|\\r/g, "")) | ||
if (config.VERBOSE) |
) | ||
if (savedOriginalTxsCount > 0) | ||
Logger.mainLogger.debug( | ||
`Clean ${savedOriginalTxsCount} old originalTxsData from the processed originalTxsData cache on cycle ${getCurrentCycleCounter()}` |
Check warning
Code scanning / CodeQL
Log injection Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
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 a malicious user can manipulate the log entries by providing input with special characters that are interpreted when the log output is displayed.
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 user from injecting new log entries by providing input with newline characters.
In the file src/API.ts
, we need to sanitize the gossipPayload
variable before logging it. We can do this by replacing all newline characters in the gossipPayload
variable with an empty string.
In the file src/Data/Collector.ts
, we need to sanitize the getCurrentCycleCounter()
function before logging it. We can do this by converting the function's return value to a string and then replacing all newline characters in the string with an empty string.
-
Copy modified line R1273
@@ -1272,3 +1272,3 @@ | ||
Logger.mainLogger.debug( | ||
`Clean ${savedOriginalTxsCount} old originalTxsData from the processed originalTxsData cache on cycle ${getCurrentCycleCounter()}` | ||
`Clean ${savedOriginalTxsCount} old originalTxsData from the processed originalTxsData cache on cycle ${getCurrentCycleCounter().toString().replace(/\n|\r/g, "")}` | ||
) |
-
Copy modified line R841
@@ -840,3 +840,3 @@ | ||
if (config.VERBOSE) | ||
Logger.mainLogger.debug('Gossip Data received', StringUtils.safeStringify(gossipPayload)) | ||
Logger.mainLogger.debug('Gossip Data received', StringUtils.safeStringify(gossipPayload).replace(/\n|\r/g, "")) | ||
const result = Collector.validateGossipData(gossipPayload) |
No description provided.