GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java: Regex injection · Pull Request #5704 · github/codeql

Conversation

@ghost

@ghost ghost commented Apr 16, 2021

Copy link
Copy Markdown

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
edvraa
Regex injection
29e3206
@ghost
ghost self-requested a review as a code owner April 16, 2021 20:33
@github-actions github-actions Bot added documentation Java labels Apr 16, 2021
@ghost ghost changed the title [Java]: Regex injection Java: Regex injection Apr 16, 2021
@Marcono1234

Marcono1234 commented Apr 18, 2021

Copy link
Copy Markdown
Contributor

Maybe it would be good to cover Apache Commons Lang's RegExUtils as well since there is already some support for that class provided by the Java CodeQL library, see #5339.

It might be useful to model all methods accepting regex arguments in some way so future queries (e.g. DoS from hardcoded regex patterns, or erroneous regex patterns) can reuse it. Though I am not a member of this project, so I can't tell if and how that should be implemented.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@smowton smowton assigned tamasvajk Apr 19, 2021
@ghost

ghost commented Apr 19, 2021

Copy link
Copy Markdown
Author

Maybe it would be good to cover Apache Commons Lang's RegExUtils

Good idea, will do that.

Marcono1234 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

edvraa added 2 commits April 21, 2021 13:08
edvraa
Add RegExUtils
13655b5
edvraa
comments
452ec8c
Marcono1234
Marcono1234 reviewed Apr 21, 2021
View reviewed changes

@Marcono1234 Marcono1234 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The following review comments are mostly cosmetic.

An interesting aspect might also be the replacement string of the replace calls. That string supports referencing captured groups (see documentation), including $0 to reference the complete match. This might be abusable:

"1234567890".replaceFirst("\\d+", "$0$0$0$0$0$0$0$0$0$0$0")
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

Depending on how large the match is and whether there are any length restrictions on the replacement string this could allow DoS attacks through high memory usage.
What do you think? (Though the projects on which I tried a query checking for this had no results)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql
}
}

abstract class Sanitizer extends DataFlow::ExprNode { }

@Marcono1234 Marcono1234 Apr 21, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Since only RegExpSanitizationCall is extending this class it might be best to remove it and have RegExpSanitizationCall directly extend DataFlow::ExprNode (unless this pull request is not finished yet and you are planning to add more sanitizers).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ghost ghost Apr 22, 2021

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You never know when pull request is finished :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

edvraa added 3 commits April 22, 2021 09:44
edvraa
Use TypeString
9774b24
edvraa
Use set literal expression
86444bf
edvraa
Add a test
ade2383
@ghost

ghost commented Apr 22, 2021

Copy link
Copy Markdown
Author

The following review comments are mostly cosmetic.

An interesting aspect might also be the replacement string of the replace calls. That string supports referencing captured groups (see documentation), including $0 to reference the complete match. This might be abusable:

"1234567890".replaceFirst("\\d+", "$0$0$0$0$0$0$0$0$0$0$0")
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

Depending on how large the match is and whether there are any length restrictions on the replacement string this could allow DoS attacks through high memory usage.
What do you think? (Though the projects on which I tried a query checking for this had no results)

User input in any of the regex arguments could alter the program logic. In this case I think it can only throw out of memory exception, that is far away from CPU intensive regex DoS.

Marcono1234 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Marcono1234
Marcono1234 reviewed Apr 22, 2021
View reviewed changes
Comment thread java/ql/src/experimental/Security/CWE/CWE-730/RegexInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost mentioned this pull request Apr 26, 2021
[Java]: CWE-730 Regex injection github/securitylab#351
Closed
1 task
@tamasvajk

tamasvajk commented Apr 27, 2021

Copy link
Copy Markdown
Contributor

I started an LGTM analysis of this query.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

edvraa
Remove Class cast
5eb96c1
@ghost

ghost commented May 24, 2021

Copy link
Copy Markdown
Author

Ping

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@smowton

smowton commented May 27, 2021

Copy link
Copy Markdown
Contributor

@tamasvajk

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tamasvajk

tamasvajk commented May 27, 2021

Copy link
Copy Markdown
Contributor

@smowton I asked @aschackmull to have a final look. He'll check the PR next week.

smowton reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@smowton smowton assigned aschackmull May 27, 2021
@aschackmull

aschackmull commented Jun 1, 2021

Copy link
Copy Markdown
Contributor

Looks ok to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aschackmull
aschackmull approved these changes Jun 1, 2021
View reviewed changes
@aschackmull
aschackmull merged commit a4661e1 into github:main Jun 1, 2021
@ghost ghost mentioned this pull request Aug 18, 2021
Java: Regex injection github/securitylab#423
Closed
@jcogs33 jcogs33 mentioned this pull request Nov 1, 2022
Java: Promote regex injection query from experimental #11070
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@tamasvajk tamasvajk

@aschackmull aschackmull

Labels

documentation Java

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Marcono1234 @tamasvajk @smowton @aschackmull
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.