Skip to content

Commit fd30d3e

Browse files
Copilotpelikhan
andauthored
fix: remove all typeof core guards from sanitize_content_core.cjs
A shim is always loaded in Node.js environments, so the guards are unnecessary. Removed all 13 remaining typeof core !== "undefined" guard wrappers across the file (URL redaction, mention escaping, template delimiter detection, GitHub reference filtering). Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d67f99b2-824d-43ca-a316-13659e8da6a5 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent f8a9047 commit fd30d3e

1 file changed

Lines changed: 16 additions & 46 deletions

File tree

actions/setup/js/sanitize_content_core.cjs

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,8 @@ function sanitizeUrlProtocols(s) {
208208
const domainLower = domain.toLowerCase();
209209
const sanitized = sanitizeDomainName(domainLower);
210210
const truncated = domainLower.length > 12 ? domainLower.substring(0, 12) + "..." : domainLower;
211-
if (typeof core !== "undefined" && core.info) {
212-
core.info(`Redacted URL: ${truncated}`);
213-
}
214-
if (typeof core !== "undefined" && core.debug) {
215-
core.debug(`Redacted URL (full): ${match}`);
216-
}
211+
core.info(`Redacted URL: ${truncated}`);
212+
core.debug(`Redacted URL (full): ${match}`);
217213
addRedactedDomain(domainLower);
218214
// Return sanitized domain format
219215
return sanitized ? `(${sanitized}/redacted)` : "(redacted)";
@@ -224,12 +220,8 @@ function sanitizeUrlProtocols(s) {
224220
const protocol = protocolMatch[1] + ":";
225221
// Truncate the matched URL for logging (keep first 12 chars + "...")
226222
const truncated = match.length > 12 ? match.substring(0, 12) + "..." : match;
227-
if (typeof core !== "undefined" && core.info) {
228-
core.info(`Redacted URL: ${truncated}`);
229-
}
230-
if (typeof core !== "undefined" && core.debug) {
231-
core.debug(`Redacted URL (full): ${match}`);
232-
}
223+
core.info(`Redacted URL: ${truncated}`);
224+
core.debug(`Redacted URL (full): ${match}`);
233225
addRedactedDomain(protocol);
234226
}
235227
return "(redacted)";
@@ -288,12 +280,8 @@ function sanitizeUrlDomains(s, allowed) {
288280
// Redact the domain but preserve the protocol and structure for debugging
289281
const sanitized = sanitizeDomainName(hostname);
290282
const truncated = hostname.length > 12 ? hostname.substring(0, 12) + "..." : hostname;
291-
if (typeof core !== "undefined" && core.info) {
292-
core.info(`Redacted URL: ${truncated}`);
293-
}
294-
if (typeof core !== "undefined" && core.debug) {
295-
core.debug(`Redacted URL (full): ${match}`);
296-
}
283+
core.info(`Redacted URL: ${truncated}`);
284+
core.debug(`Redacted URL (full): ${match}`);
297285
addRedactedDomain(hostname);
298286
// Return sanitized domain format
299287
return sanitized ? `(${sanitized}/redacted)` : "(redacted)";
@@ -356,9 +344,7 @@ function neutralizeAllMentions(s) {
356344
// This prevents bypass patterns like "test_@user" from escaping sanitization
357345
return s.replace(/(^|[^A-Za-z0-9`])@([A-Za-z0-9](?:[A-Za-z0-9_-]{0,37}[A-Za-z0-9])?(?:\/[A-Za-z0-9._-]+)?)/g, (m, p1, p2) => {
358346
// Log when a mention is escaped to help debug issues
359-
if (typeof core !== "undefined" && core.info) {
360-
core.info(`Escaped mention: @${p2} (not in allowed list)`);
361-
}
347+
core.info(`Escaped mention: @${p2} (not in allowed list)`);
362348
return `${p1}\`@${p2}\``;
363349
});
364350
}
@@ -771,9 +757,7 @@ function neutralizeTemplateDelimiters(s) {
771757
if (/\{\{/.test(result)) {
772758
if (!detectedTypes.has("jinja2")) {
773759
detectedTypes.add("jinja2");
774-
if (typeof core !== "undefined" && core.info) {
775-
core.info("Template syntax detected: Jinja2/Liquid double braces {{");
776-
}
760+
core.info("Template syntax detected: Jinja2/Liquid double braces {{");
777761
}
778762
result = result.replace(/\{\{/g, "\\{\\{");
779763
}
@@ -783,9 +767,7 @@ function neutralizeTemplateDelimiters(s) {
783767
if (/<%=/.test(result)) {
784768
if (!detectedTypes.has("erb")) {
785769
detectedTypes.add("erb");
786-
if (typeof core !== "undefined" && core.info) {
787-
core.info("Template syntax detected: ERB delimiter <%=");
788-
}
770+
core.info("Template syntax detected: ERB delimiter <%=");
789771
}
790772
result = result.replace(/<%=/g, "\\<%=");
791773
}
@@ -795,9 +777,7 @@ function neutralizeTemplateDelimiters(s) {
795777
if (/\$\{/.test(result)) {
796778
if (!detectedTypes.has("js")) {
797779
detectedTypes.add("js");
798-
if (typeof core !== "undefined" && core.info) {
799-
core.info("Template syntax detected: JavaScript template literal ${");
800-
}
780+
core.info("Template syntax detected: JavaScript template literal ${");
801781
}
802782
result = result.replace(/\$\{/g, "\\$\\{");
803783
}
@@ -807,9 +787,7 @@ function neutralizeTemplateDelimiters(s) {
807787
if (/\{#/.test(result)) {
808788
if (!detectedTypes.has("jinja2comment")) {
809789
detectedTypes.add("jinja2comment");
810-
if (typeof core !== "undefined" && core.info) {
811-
core.info("Template syntax detected: Jinja2 comment {#");
812-
}
790+
core.info("Template syntax detected: Jinja2 comment {#");
813791
}
814792
result = result.replace(/\{#/g, "\\{\\#");
815793
}
@@ -819,9 +797,7 @@ function neutralizeTemplateDelimiters(s) {
819797
if (/\{%/.test(result)) {
820798
if (!detectedTypes.has("jekyll")) {
821799
detectedTypes.add("jekyll");
822-
if (typeof core !== "undefined" && core.info) {
823-
core.info("Template syntax detected: Jekyll/Liquid directive {%");
824-
}
800+
core.info("Template syntax detected: Jekyll/Liquid directive {%");
825801
}
826802
result = result.replace(/\{%/g, "\\{\\%");
827803
}
@@ -834,7 +810,7 @@ function neutralizeTemplateDelimiters(s) {
834810
const result = applyToNonCodeRegions(s, escapeInText);
835811

836812
// Log a summary warning if any template patterns were detected
837-
if (detectedTypes.size > 0 && typeof core !== "undefined" && core.warning) {
813+
if (detectedTypes.size > 0) {
838814
core.warning(
839815
"Template-like syntax detected and escaped. " +
840816
"This is a defense-in-depth measure to prevent potential template injection " +
@@ -859,19 +835,15 @@ function buildAllowedGitHubReferences() {
859835
}
860836

861837
if (allowedRefsEnv === "") {
862-
if (typeof core !== "undefined" && core.info) {
863-
core.info("GitHub reference filtering: all references will be escaped (GH_AW_ALLOWED_GITHUB_REFS is empty)");
864-
}
838+
core.info("GitHub reference filtering: all references will be escaped (GH_AW_ALLOWED_GITHUB_REFS is empty)");
865839
return []; // Empty array means escape all references
866840
}
867841

868842
const refs = allowedRefsEnv
869843
.split(",")
870844
.map(ref => ref.trim().toLowerCase())
871845
.filter(ref => ref);
872-
if (typeof core !== "undefined" && core.info) {
873-
core.info(`GitHub reference filtering: allowed repos = ${refs.join(", ")}`);
874-
}
846+
core.info(`GitHub reference filtering: allowed repos = ${refs.join(", ")}`);
875847
return refs;
876848
}
877849

@@ -931,9 +903,7 @@ function neutralizeGitHubReferences(s, allowedRepos) {
931903
const refText = owner && repo ? `${owner}/${repo}#${issueNum}` : `#${issueNum}`;
932904

933905
// Log when a reference is escaped
934-
if (typeof core !== "undefined" && core.info) {
935-
core.info(`Escaped GitHub reference: ${refText} (not in allowed list)`);
936-
}
906+
core.info(`Escaped GitHub reference: ${refText} (not in allowed list)`);
937907

938908
return `${prefix}\`${refText}\``;
939909
}

0 commit comments

Comments
 (0)