対象のビジネスユニットで、ハードコードされたクライアントシークレットを持つスクリプトアクティビティを監査するために以下のデータエクステンション作成します。
| Field Name | Data Type | Length | Primary Key | Nullable | Default Value |
| ScriptKey | Text | 100 | No | No | Not Applicable |
| ScriptName | Text | 255 | No | No | Not Applicable |
| FoundString | Text | 100 | No | No | Not Applicable |
| AuditDate | Date | Not Applicable | No | No | Current Date |
このデータエクステンションに結果ログを記録するための SSJS アクティビティを作成する必要があります。このスクリプトは、すべてのスクリプトアクティビティのコードから特定の文字列(「client_secret」など)を検索し、WSProxy を使用して結果をデータエクステンションに挿入します。
注:subdomain、clientId、clientSecret、および mid の値が指定されていることを確認してください。この処理では REST API が利用されるため、アカウント内で適切なインストール済みパッケージを参照する必要があります。
<script runat="server">
Platform.Load("Core", "1.1.1");
try {
var subdomain = "YOUR_SUBDOMAIN";
var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";
var mid = "YOUR_MID";
var searchString = "client_secret";
var targetDEKey = "ScriptActivity_SecurityAudit";
var authUrl = "https://" + subdomain + ".auth.marketingcloudapis.com/v2/token";
var payload = {
grant_type: "client_credentials",
client_id: clientId,
client_secret: clientSecret,
account_id: mid
};
var authReq = new Script.Util.HttpRequest(authUrl);
authReq.emptyContentHandling = 0;
authReq.retries = 2;
authReq.continueOnError = true;
authReq.contentType = "application/json";
authReq.method = "POST";
authReq.postData = Stringify(payload);
var authResp = authReq.send();
var authJson = Platform.Function.ParseJSON(String(authResp.content));
var token = authJson.access_token;
var restUrl = authJson.rest_instance_url;
if (token) {
var scriptsUrl = restUrl + "automation/v1/scripts";
var scriptReq = new Script.Util.HttpRequest(scriptsUrl);
scriptReq.emptyContentHandling = 0;
scriptReq.retries = 2;
scriptReq.continueOnError = true;
scriptReq.method = "GET";
scriptReq.setHeader("Authorization", "Bearer " + token);
var scriptResp = scriptReq.send();
var scriptJson = Platform.Function.ParseJSON(String(scriptResp.content));
var items = scriptJson.items || scriptJson;
var prox = new Script.Util.WSProxy();
for (var i = 0; i < items.length; i++) {
var content = items[i].script || "";
if (content.toLowerCase().indexOf(searchString.toLowerCase()) !== -1) {
var insertProps = [
{ Name: "ScriptKey", Value: items[i].key },
{ Name: "ScriptName", Value: items[i].name },
{ Name: "FoundString", Value: searchString }
];
var result = prox.createItem("DataExtensionObject", {
CustomerKey: targetDEKey,
Properties: insertProps
});
}
}
}
} catch (error) {
Write("Error: " + Stringify(error));
}
</script>
上記の SSJS アクティビティを実行して、すべてのスクリプトアクティビティの内容を検索し、検出された脆弱なスクリプトをデータエクステンション「ScriptActivity_SecurityAudit」内にログとして記録します。
SSJS アクティビティでタイムアウト(30分)エラーが発生した場合は、REST API 呼び出し内でページネーションを実装して、スクリプトをより小さなバッチで処理する必要がある場合があります。
005317464

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.