Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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
29 changes: 29 additions & 0 deletions src/ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,35 @@ impl Log {
)
}

/// `add_warning` with `AddErrorOptions`, formatted, plus a free-standing `note:` line.
/// `redact_sensitive_information` masks a credential value in the warned line's
/// source frame; the note carries no frame.
#[cold]
pub fn add_warning_fmt_opts_with_note(
&mut self,
args: fmt::Arguments<'_>,
note_args: fmt::Arguments<'_>,
opts: AddErrorOptions<'_>,
) {
if !Kind::Warn.should_print(self.level) {
return;
}
let notes: Box<[Data]> = Box::new([range_data(None, Range::NONE, alloc_print(note_args))]);
let text = alloc_print(args);
self.add_formatted_msg(
Kind::Warn,
opts.source,
Range {
loc: opts.loc,
len: opts.len,
},
text,
notes,
true,
opts.redact_sensitive_information,
)
}

/// Use a bun.sys.Error's message in addition to some extra context.
pub fn add_sys_error(&mut self, e: &bun_sys::Error, args: fmt::Arguments<'_>) {
let Some((tag_name, sys_errno)) = e.get_error_code_tag_name() else {
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 @@ -1692,6 +1692,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(crate) 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 @@ -1967,6 +1976,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