From 7ab52a81a7941a5f819e9949d229dec828bc82e4 Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 5 Dec 2025 10:22:31 +0100 Subject: [PATCH] JS: Add environment variable to opt out of the behaviour if needed --- .../src/com/semmle/js/extractor/AutoBuild.java | 7 +++++-- .../js/extractor/EnvironmentVariables.java | 8 ++++++++ .../semmle/js/extractor/ExtractorConfig.java | 17 +++++++++++++++++ .../semmle/js/extractor/ScriptExtractor.java | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index 416fa237e97..d8889781921 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -408,8 +408,10 @@ public class AutoBuild { for (String extension : fileTypes.keySet()) patterns.add("**/*" + extension); // exclude files whose name strongly suggests they are minified - patterns.add("-**/*.min.js"); - patterns.add("-**/*-min.js"); + if (!EnvironmentVariables.allowMinifiedFiles()) { + patterns.add("-**/*.min.js"); + patterns.add("-**/*-min.js"); + } // exclude `node_modules` and `bower_components` patterns.add("-**/node_modules"); @@ -1074,6 +1076,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set config = config.withSourceType(getSourceType()); config = config.withVirtualSourceRoot(virtualSourceRoot); if (defaultEncoding != null) config = config.withDefaultEncoding(defaultEncoding); + config = config.withAllowMinified(EnvironmentVariables.allowMinifiedFiles()); return config; } diff --git a/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java b/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java index f2ac4227589..9d883960256 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java +++ b/javascript/extractor/src/com/semmle/js/extractor/EnvironmentVariables.java @@ -101,4 +101,12 @@ public class EnvironmentVariables { public static boolean isActionsExtractor() { return Env.systemEnv().getNonEmpty(CODEQL_EXTRACTOR_ACTIONS_WIP_DATABASE_ENV_VAR) != null; } + + public static boolean allowMinifiedFiles() { + String env = Env.systemEnv().getNonEmpty("CODEQL_EXTRACTOR_JAVASCRIPT_ALLOW_MINIFIED_FILES"); + if (env == null) { + return false; // default is to not allow minified files + } + return Boolean.parseBoolean(env); + } } diff --git a/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java b/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java index 884d0744694..538ac1a4367 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java @@ -205,6 +205,9 @@ public class ExtractorConfig { /** Should parse errors be reported as violations instead of aborting extraction? */ private boolean tolerateParseErrors; + /** Should minified files be allowed? */ + private boolean allowMinified; + /** How should HTML files be extracted? */ private HtmlPopulator.Config htmlHandling; @@ -236,6 +239,7 @@ public class ExtractorConfig { this.sourceType = SourceType.AUTO; this.htmlHandling = HtmlPopulator.Config.ELEMENTS; this.tolerateParseErrors = true; + this.allowMinified = false; if (experimental) { this.mozExtensions = true; this.jscript = true; @@ -258,6 +262,7 @@ public class ExtractorConfig { this.v8Extensions = that.v8Extensions; this.e4x = that.e4x; this.tolerateParseErrors = that.tolerateParseErrors; + this.allowMinified = that.allowMinified; this.fileType = that.fileType; this.sourceType = that.sourceType; this.htmlHandling = that.htmlHandling; @@ -357,6 +362,16 @@ public class ExtractorConfig { return res; } + public boolean isAllowMinified() { + return allowMinified; + } + + public ExtractorConfig withAllowMinified(boolean allowMinified) { + ExtractorConfig res = new ExtractorConfig(this); + res.allowMinified = allowMinified; + return res; + } + public boolean hasFileType() { return fileType != null; } @@ -467,6 +482,8 @@ public class ExtractorConfig { + e4x + ", tolerateParseErrors=" + tolerateParseErrors + + ", allowMinified=" + + allowMinified + ", htmlHandling=" + htmlHandling + ", fileType=" diff --git a/javascript/extractor/src/com/semmle/js/extractor/ScriptExtractor.java b/javascript/extractor/src/com/semmle/js/extractor/ScriptExtractor.java index 6c9bfd2725c..bff9ccddad6 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ScriptExtractor.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ScriptExtractor.java @@ -62,7 +62,7 @@ public class ScriptExtractor implements IExtractor { LocationManager locationManager = textualExtractor.getLocationManager(); String source = textualExtractor.getSource(); - if (isMinified(source)) { + if (!config.isAllowMinified() && isMinified(source)) { return ParseResultInfo.skipped("File appears to be minified."); }