Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
52 changes: 52 additions & 0 deletions src/ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,34 @@
)
}

/// `add_warning_opts`, formatted, plus a free-standing `note:` line. The frame
/// redaction applies to the warned line; the note carries no source 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 Expand Up @@ -2414,6 +2442,30 @@
})
}

/// `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()
})
}

Check warning on line 2467 in src/ast/lib.rs

View check run for this annotation

Claude / Claude Code Review

Dead code: add_warning_opts is never called

nit: `add_warning_opts` has no callers — the one caller in `resolve_credentials` was migrated to `add_warning_fmt_opts_with_note` when the `note:` line was added, leaving this behind (the PR description still names it as the entry point). Either delete it or, if it's kept as the warning twin of `add_error_opts` for symmetry, the description should be updated to reflect that the note-carrying variant is what actually runs.
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