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

Expand RabbitMQ validator to check loose credentials expressions. #788

Merged
merged 4 commits into from
Jul 18, 2023

Conversation

yongyan-gh
Copy link
Collaborator

Changes

  • Update SEC101/041.RabbitMqCredentials validator to check for loose credentials. e.g.
{
  "settings": [
    { "name": "RABBITMQ HOST", "value": "12.23.45.78" },
    { "name": "RABBITMQ PASSWORD", "value": "..." },
    { "name": "RABBITMQ PORT", "value": "5672" }, 
    { "name": "RABBITMQ USERNAME", "value": "guest" },
    ...
  ]
}
...
env:
    RABBITQ_HOST: ...
    RABBITMQ_USERNAME: ...
    RABBITMQ_PASSWORD: ...
    RABBITMQ_VHOST: ...
  • Ignore the password in within common variable context e.g. $(...) {...} [...]
  • Make the port number and virtual host name optional.
  • Update official RabbitMQ.Client package to latest version.

HulonJenkins
HulonJenkins previously approved these changes Jul 17, 2023
@@ -18,12 +18,19 @@ protected override IEnumerable<ValidationResult> IsValidStaticHelper(IDictionary
{
if (!groups.TryGetNonEmptyValue("id", out FlexMatch id) ||
!groups.TryGetNonEmptyValue("host", out FlexMatch host) ||
!groups.TryGetNonEmptyValue("secret", out FlexMatch secret) ||
!groups.TryGetNonEmptyValue("resource", out FlexMatch resource))
!groups.TryGetNonEmptyValue("secret", out FlexMatch secret))
Copy link
Collaborator

@HulonJenkins HulonJenkins Jul 17, 2023

Choose a reason for hiding this comment

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

We shouldn't need this if statement check for id, host, and secret now that these are required in the regex. Can just be string id = groups["id"].value for all 3 #Resolved

@@ -48,5 +48,24 @@ public static bool LikelyPowershellVariable(string input)

return true;
}

public static bool PasswordIsInCommonVariableContext(string secret)
Copy link
Collaborator

Choose a reason for hiding this comment

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

InCommo

Can our rules in SPMI use this function as well after this is merged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the function I copied from your previous implementation. The other projects has a reference to Security can use it.

@@ -129,9 +129,14 @@
$SEC101/038.PostgreSqlCredentialsAdoSecret=(?i)(?:password|pwd)\s*=\s*(?P<secret>[^,;"'<\s]{8,128})(?:[,;"'<\s]|$)
$SEC101/038.PostgreSqlCredentialsAdoResource=(?i)(?:database|db|dbname)\s*=\s*(?P<resource>[^,;"'=|&\]\[><\s]+)(?:[,;"'=|&\]\[><\s]|$)

$SEC101/041.RabbitMqCredentials=(?i)amqps?:\/\/(?P<id>[^:"]+):(?P<secret>[^@\s]+)@(?P<host>[\w_\-\:]+)\/(?P<resource>[\w]+)(?:[^0-9a-z]|$)
$SEC101/041.RabbitMqCredentials=(?i)amqps?:\/\/(?P<id>[^:"]+):(?P<secret>[^@\s]+)@(?P<host>[\w_-]+)(?::?(?P<port>[0-9]{4,5}))?\/(?P<resource>[\w]+)?(?:[^0-9a-z]|$)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The change here is to add capture group for "port" explicitly and make the "resource" group optional

@HulonJenkins HulonJenkins dismissed their stale review July 18, 2023 16:07

revoking review

@HulonJenkins HulonJenkins merged commit c0e4df8 into main Jul 18, 2023
2 checks passed
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.

2 participants