Skip to content

Sanitize backend keys with .. in them.#36303

Merged
mdwn merged 2 commits intomasterfrom
mike.wilson/sanitize-denies-double-dot
Jan 8, 2024
Merged

Sanitize backend keys with .. in them.#36303
mdwn merged 2 commits intomasterfrom
mike.wilson/sanitize-denies-double-dot

Conversation

@mdwn
Copy link
Copy Markdown
Contributor

@mdwn mdwn commented Jan 4, 2024

Backend keys with .. in them have been added to the regex for patterns in keys that are denied.

changelog: Resources named . and .. are no longer allowed. Please review the resources in your Teleport instance and rename any resources with these names before upgrading.

Backend keys with .. in them have been added to the regex for patterns in
keys that are denied.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 4, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

Comment thread lib/backend/sanitize.go Outdated
Comment on lines +40 to +43
var denyPatterns = []string{
"//",
"..",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we sure this is the exhaustive list? Is . valid? What about ../. or ..//?

Copy link
Copy Markdown
Contributor

@jentfoo jentfoo Jan 4, 2024

Choose a reason for hiding this comment

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

I can confirm that . is an additional case we need to cover here. I was unable to reproduce this issue with a combination of . and /, but if we can be more restrictive that would be best.

edit** could we require at least one alpha or numeric character to be present?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This definitely isn't exhaustive. . is valid, however, because we create .locks pretty regularly. The other two will be caught by this because this is just doing a simple bytes.Contains.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to protect against the case where . is the entire name. I edited my prior comment, but in general I think we should just require at least one alpha or numeric character to be present.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking that we should adjust this so that it's the following:

  • . is the full name
  • .. is the full name
  • ../ is found anywhere in the string
  • // is found anywhere in the string.

Thoughts?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have we considered just running path.Clean() on this thing and seeing if the output matches the input?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It sounds like what we are trying to say is:

  • A path component can't be empty (// and variants)
  • A path component can't be solely composed of dots or other special characters (must have a letter?)

I don't mind landing the change, but I'm unclear why we care. It's not like these are actual filepaths or would be resolved as such. Could anyone give a bit more background on this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried path.Clean(). I imagine I could make it work, but it doesn't quite work as well when there's no leading slash. I'm a little hesitant to munge the string too much to force a match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've adjusted this to use some fancier regexes that will allow ..string as a name, which the UI is able to parse without issue.

Copy link
Copy Markdown
Contributor

@fspmarshall fspmarshall left a comment

Choose a reason for hiding this comment

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

LGTM once /path/to/./val and /path/to/. are covered.

Comment thread lib/backend/sanitize.go Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 5, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@mdwn mdwn added the no-changelog Indicates that a PR does not require a changelog entry label Jan 5, 2024
@mdwn mdwn enabled auto-merge January 5, 2024 14:31
@mdwn mdwn removed the no-changelog Indicates that a PR does not require a changelog entry label Jan 5, 2024
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 5, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@smallinsky smallinsky self-requested a review January 8, 2024 14:08
Comment thread lib/backend/sanitize_test.go
@mdwn mdwn added this pull request to the merge queue Jan 8, 2024
Merged via the queue into master with commit 78569f9 Jan 8, 2024
@mdwn mdwn deleted the mike.wilson/sanitize-denies-double-dot branch January 8, 2024 14:30
@public-teleport-github-review-bot
Copy link
Copy Markdown

@mdwn See the table below for backport results.

Branch Result
branch/v12 Create PR
branch/v13 Create PR
branch/v14 Create PR

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants