Content Builder のアセットにハードコードされたシークレットがないか監査したいビジネスユニットにおいて、以下の定義でデータエクステンション(DE)を作成します。
データエクステンション(Asset_SecurityAudit)のフィールド定義
| 項目名 | テータ型 | 長さ | 主キー | Null 許容 | デフォルト値 |
| AssetId | テキスト |
100 |
No | No | なし |
| AssetName | テキスト | 255 | No | No | なし |
| AssetType | テキスト | 100 | No | No | なし |
| FoundString | テキスト | 100 | No | No | なし |
| AuditDate | 日付 | - | No | No |
現在の日付 |
DE を作成した後、Content Builder の REST API 経由でアセットを取得し、結果をログとして記録する SSJS アクティビティを作成する必要があります。このスクリプトはアセットをページネーションを利用して取得し、各アセットの JSON 内から特定の文字列(例:「clientsecret」)を検索し、WSProxy を使って結果をデータエクステンションに挿入します。
注意: subdomain、clientId、clientSecret、mid の各値が指定されていることを確認してください。この処理は REST API を利用するため、アカウント内で saved_content_read スコープを持つ適切な インストール済みパッケージを作成する必要があります。
<script runat="server">
Platform.Load("Core", "1.1.1");
try {
// 1. Set up your variables
var subdomain = "YOUR_SUBDOMAIN";
var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR_CLIENT_SECRET";
var mid = "YOUR_MID";
var searchString = "client_secret";
var targetDEKey = "Asset_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
};
// 2. Authenticate
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 prox = new Script.Util.WSProxy();
var page = 1;
var pageSize = 50;
var hasMore = true;
// 3. Loop through Asset pages
while (hasMore && page <= 500) { // Safety cap at 500 pages to prevent infinite loops
var assetsUrl = restUrl + "asset/v1/content/assets?$page=" + page + "&$pagesize=" + pageSize;
var assetReq = new Script.Util.HttpRequest(assetsUrl);
assetReq.emptyContentHandling = 0;
assetReq.retries = 2;
assetReq.continueOnError = true;
assetReq.method = "GET";
assetReq.setHeader("Authorization", "Bearer " + token);
var assetResp = assetReq.send();
var assetJson = Platform.Function.ParseJSON(String(assetResp.content));
var items = assetJson.items || [];
// 4. Search and insert
for (var i = 0; i < items.length; i++) {
// Stringify the entire asset object to catch nested content, views, and HTML
var itemString = Stringify(items[i]).toLowerCase();
if (itemString.indexOf(searchString.toLowerCase()) !== -1) {
var assetId = String(items[i].id);
var assetName = items[i].name || "Unknown";
var assetType = items[i].assetType ? items[i].assetType.name : "Unknown";
var insertProps = [
{ Name: "AssetId", Value: assetId },
{ Name: "AssetName", Value: assetName },
{ Name: "AssetType", Value: assetType },
{ Name: "FoundString", Value: searchString }
];
prox.createItem("DataExtensionObject", {
CustomerKey: targetDEKey,
Properties: insertProps
});
}
}
// 5. Check if we need to fetch the next page
if (items.length < pageSize) {
hasMore = false;
} else {
page++;
}
}
}
} catch (error) {
Write("Error: " + Stringify(error));
}
</script>上記の SSJS アクティビティを実行して、すべての Content Builder のアセットを検索し、脆弱性が確認されたアセットを DE Asset_SecurityAudit に記録します。
このスクリプトはページネーションを使用しているため、50 件ずつのバッチでアセットを自動的に参照します。アセットライブラリが非常に大きい場合、SSJS アクティビティがタイムアウト(30分)でエラーになることがありますが、その場合はスクリプト内の $page 変数を手動で調整して、前回のタイムアウト箇所から再開できます。
005317466

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.