Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,30 @@ impl Log {
})
}

/// `add_warning`, with `AddErrorOptions`. Use when the offending source line can
/// contain a credential: `redact_sensitive_information` masks the value in the frame.
#[cold]
pub fn add_warning_opts(&mut self, text: Str, opts: AddErrorOptions<'_>) {
if !Kind::Warn.should_print(self.level) {
return;
}
self.warnings += 1;
let data = self.tracked_range_data(
opts.source,
Range {
loc: opts.loc,
len: opts.len,
},
text,
);
self.add_msg(Msg {
kind: Kind::Warn,
data,
redact_sensitive_information: opts.redact_sensitive_information,
..Default::default()
})
}
Comment thread
robobun marked this conversation as resolved.
Outdated

// TODO(dylan-conway): rename and replace `addError`
#[cold]
pub fn add_error_opts(&mut self, text: Str, opts: AddErrorOptions<'_>) {
Expand Down
22 changes: 22 additions & 0 deletions src/bun_core/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,15 @@ impl RedactedKeywords {
b"_auth" | b"_authToken" | b"token" | b"_password" | b"email"
)
}

/// Whether `s` STARTS WITH a redacted keyword. The ini parser recognizes a
/// credential option by substring, so redaction must be at least as loose:
/// `_auth` covers `_authToken`, and trailing junk stays redacted.
pub fn has_prefix(s: &[u8]) -> bool {
[b"_auth".as_slice(), b"token", b"_password", b"email"]
.iter()
.any(|k| s.starts_with(k))
}
}

impl Display for QuickAndDirtyJavaScriptSyntaxHighlighter<'_> {
Expand Down Expand Up @@ -2013,6 +2022,19 @@ impl Display for QuickAndDirtyJavaScriptSyntaxHighlighter<'_> {
break 'try_redact;
}

// An ini credential key may be quoted:
// `"//host/:_authToken"=secret`. The identifier path
// never sees it, so arm the value redaction here, at
// least as loosely as the ini parser matches options.
let mut rest: &[u8] = inner;
while let Some(colon) = strings::index_of_char(rest, b':') {
rest = &rest[colon as usize + 1..];
if RedactedKeywords::has_prefix(rest) {
should_redact_value = true;
break;
}
}
Comment thread
robobun marked this conversation as resolved.
Outdated

if inner.len() == 36 && strings::is_uuid(inner) {
write!(writer, "{}\x1b[32m{}", Output::RESET, char_ as char)?;
splat_byte_all(writer, b'*', 36)?;
Expand Down
Loading
Loading