-
Notifications
You must be signed in to change notification settings - Fork 0
security: Tier 1 hardening (wrapper integrity, token redaction, log sanitization) #39
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
MarketDataApp
wants to merge
1
commit into
main
Choose a base branch
from
security/tier1-hardening
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.marketdata.sdk; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Neutralize untrusted text (API response strings such as {@code errmsg}, or malformed | ||
| * date/timestamp cells) before it is embedded in an exception message or log line. | ||
| * | ||
| * <p>A hostile or buggy server controls these strings. Copied verbatim into a {@code ParseError} | ||
| * message that a consumer then logs, embedded carriage-returns/newlines let an attacker forge or | ||
| * split log entries, and ANSI escape sequences can spoof a terminal. This collapses every ISO | ||
| * control character (C0/C1 range, including {@code CR}, {@code LF}, {@code TAB}, and the {@code | ||
| * ESC} that introduces ANSI sequences) to a single space, and caps the length so a 20 MB | ||
| * response string (Jackson's default ceiling) can't blow up a log line. | ||
| */ | ||
| final class LogSafe { | ||
|
|
||
| /** Longest untrusted fragment we echo into a message; the rest is elided. */ | ||
| static final int MAX_LEN = 200; | ||
|
|
||
| private LogSafe() {} | ||
|
|
||
| /** | ||
| * Sanitize {@code raw} for safe inclusion in a log/exception message. Never returns {@code null}. | ||
| */ | ||
| static String sanitize(@Nullable String raw) { | ||
| if (raw == null) { | ||
| return ""; | ||
| } | ||
| String truncated = raw.length() > MAX_LEN ? raw.substring(0, MAX_LEN) + "…" : raw; | ||
| StringBuilder out = new StringBuilder(truncated.length()); | ||
| for (int i = 0; i < truncated.length(); i++) { | ||
| char c = truncated.charAt(i); | ||
| out.append(Character.isISOControl(c) ? ' ' : c); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Unfiltered non-ISO-control Unicode — LogSafe.sanitize doesn't neutralize U+2028/U+2029 (line/paragraph separators) or U+202E (RTL override); they survive and can break a line in some log viewers or enable bidi visual spoofing. |
||
| } | ||
| return out.toString(); | ||
| } | ||
| } | ||
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
Binary file not shown.
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.
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.
NIT: Truncation can split a surrogate pair — substring(0, MAX_LEN) may leave a lone surrogate when cutting; cosmetic (replacement char in the log), no security impact.