Skip to content

Conversation

@Sija
Copy link
Contributor

@Sija Sija commented Dec 31, 2025

Resolves #12928

@Sija Sija force-pushed the fix-12928 branch 2 times, most recently from ca0a678 to a01cf06 Compare January 1, 2026 02:54
@Sija
Copy link
Contributor Author

Sija commented Jan 2, 2026

I've added a suggestion from #12928 (comment) and filename validation to ensure there ain't anything funky going on, since now when the filename is treated as a regular string, it creates a new abuse vector.

Comment on lines +2458 to +2465
private def valid_filename?(filename)
filename
.each_char
.none?(&.in?(
'\0', '\a', '\b', '\n', '\r', '\t', '\v', '\f', '\e',
*UNICODE_BIDI_CONTROL_CHARACTERS,
))
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do we really need this validation? I would expect any invalid character leads to a decent error message already?
FWIW, these characters could already be used in their literal (non-escaped) form inside a loc pragma.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do we really need this validation? I would expect any invalid character leads to a decent error message already?

Yes, we do; otherwise, these characters might become part of the filename string - as they're not invalid (from the string PoV), just unwanted in this particular context.

FWIW, these characters could already be used in their literal (non-escaped) form inside a loc pragma.

Some of them, yes (which depend on the parsing logic), but not anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, these characters may be unwanted yet valid. But do we need to ensure that? What kind of bad things could happen if we leave this validation out?

private def append_loc(str, filename, line_number, column_number)
str << %(#<loc:")
str << filename
str << escape_filename(filename)
Copy link
Member

@straight-shoota straight-shoota Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: We should be able to use String#inspect here. It produces a properly escaped string literal.

Suggested change
str << escape_filename(filename)
filename.inspect(str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ECR breaks if filename contains quotation marks

2 participants