Skip to content
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

Fix code scanning alerts #40

Closed
1 of 4 tasks
jordanpadams opened this issue Sep 22, 2023 · 9 comments · Fixed by #41
Closed
1 of 4 tasks

Fix code scanning alerts #40

jordanpadams opened this issue Sep 22, 2023 · 9 comments · Fixed by #41
Assignees
Labels
B14.0 B14.1 bug Something isn't working s.high

Comments

@jordanpadams
Copy link
Member

jordanpadams commented Sep 22, 2023

Tracking issue for:

These issues are unlikely to occur, but we should sanitize these messages in the event there is a man-in-middle attack or something where harvest/registry-mgr queries some faked "OpenSearch" or something like that.

@alexdunnjpl
Copy link
Contributor

In order

  1. Log message is a JSON dump. Unless sanitizing out newlines is sufficient sanitization, the risk must be accepted or the log message removed
  2. Same as previous
  3. The input-derived variables can be newline-stripped, or the LIDVID can be filtered/replaced with a regex and the message can be stripped of problematic characters (which? we don't know prima-facie all characters which should be allowed, so we can't regex filter)
  4. Same as previous

@jordanpadams could you please weigh in on these?

@jordanpadams
Copy link
Member Author

In order

  1. Log message is a JSON dump. Unless sanitizing out newlines is sufficient sanitization, the risk must be accepted or the log message removed
  2. Same as previous
  3. The input-derived variables can be newline-stripped, or the LIDVID can be filtered/replaced with a regex and the message can be stripped of problematic characters (which? we don't know prima-facie all characters which should be allowed, so we can't regex filter)
  4. Same as previous

@alexdunnjpl per the comment in the resolution for the log injection, can we do something like this? If it doesn't make sense, that is fine too. Just want to make sure we are addressing it if we can.

        // The regex check here, allows only alphanumeric characters to pass.
        // Hence, does not result in log injection
        if (username.matches("\\w*")) {
        }

@alexdunnjpl
Copy link
Contributor

alexdunnjpl commented Sep 27, 2023

@jordanpadams that allowlist approach is most-desirable, but relies on knowing all possible allowable content and being able to differentiate between allowable and invalid content prima facie (with failures being logged as generic messages without the user-supplied value)

In the case of arbitrary JSON content, that could be anything, and is very likely to include line breaks, so it's necessary to identify all undesirable characters and remove them - there's no point in retaining the log message otherwise because its sole purpose is to dump the content for viewing.

I tend to agree with your comments about these being trivial attacks predicated upon an already-existing Very Bad Situation. The exception being this log which is amenable to just stripping out offending characters or using an allowlist approach.

@alexdunnjpl
Copy link
Contributor

@alexdunnjpl to close individual issues and note justification in each case

@tloubrieu-jpl
Copy link
Member

@alexdunnjpl @jordanpadams , similar alerts still show in the analysis report, see https://github.com/NASA-PDS/registry-common/security/code-scanning . Does something need to be done ?

@tloubrieu-jpl tloubrieu-jpl reopened this Jan 29, 2024
@tloubrieu-jpl
Copy link
Member

Note that @gxtchen came up with that question above during I&T.

@alexdunnjpl
Copy link
Contributor

I don't know why those are just coming up as of two days ago... will look into the individual messages. What's the level of urgency?

@jordanpadams
Copy link
Member Author

Per the log injection stuff, I think we just need to review them and either remove the logging from the code, or close them out as no longer a risk.

@tloubrieu-jpl
Copy link
Member

The issues where either new lines or code or because the code changed the line numbers were different and the alerts were raised again. I went though them oe by one and dismissed them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B14.0 B14.1 bug Something isn't working s.high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants