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

[Improvement] add alert script path check #15752

Merged
merged 1 commit into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/docs/en/guide/alert/script.md
Expand Up @@ -7,11 +7,11 @@ The following shows the `Script` configuration example:

## Parameter Configuration

| **Parameter** | **Description** |
|---------------|--------------------------------------------------|
| User Params | User defined parameters will pass to the script. |
| Script Path | The file location path in the server. |
| Type | Support `Shell` script. |
| **Parameter** | **Description** |
|---------------|-------------------------------------------------------------|
| User Params | User defined parameters will pass to the script. |
| Script Path | The file location path in the server, only support .sh file |
| Type | Support `Shell` script. |

### Note

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/zh/guide/alert/script.md
Expand Up @@ -12,7 +12,7 @@

* 脚本路径

> 脚本在服务器上的文件位置
> 脚本在服务器上的文件位置,只支持.sh后缀的文件

* 脚本类型

Expand Down
Expand Up @@ -69,6 +69,11 @@ private AlertResult executeShellScript(String title, String content) {
alertResult.setMessage("shell script not support windows os");
return alertResult;
}
if (!scriptPath.endsWith(".sh")) {
alertResult.setMessage("shell script is invalid, only support .sh file");
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for users to put something like reboot in the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it seems we can't limit user custom script content. If add a blacklist, it is easy to miss some keys.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, we have to deprecate this plugin in the future. I think users tend to deploy a centralized alert server, which is different from worker and makes the alert server more vulnerable.

return alertResult;
}

// validate script path in case of injections
File shellScriptFile = new File(scriptPath);
// validate existence
Expand Down
Expand Up @@ -79,6 +79,16 @@ public void testPathNPE() {
Assertions.assertEquals("false", alertResult.getStatus());
}

@Test
public void testPathError() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_PATH, "/usr/sbin/abc");
ScriptSender scriptSender = new ScriptSender(scriptConfig);
AlertResult alertResult;
alertResult = scriptSender.sendScriptAlert("test path NPE", "test content");
Assertions.assertEquals("false", alertResult.getStatus());
Assertions.assertTrue(alertResult.getMessage().contains("shell script is invalid, only support .sh file"));
}

@Test
public void testTypeIsError() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, null);
Expand Down