Skip to content

Commit

Permalink
LDEV-5013 - make sure debugging data are not logged
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 18, 2024
1 parent ba7938d commit 4ee2465
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 61 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/lucee/runtime/CFMLFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.type.util.ListUtil;
import lucee.runtime.util.PageContextUtil;
import lucee.servlet.http.HTTPServletImpl;

/**
Expand Down Expand Up @@ -580,7 +581,7 @@ public Array getInfo() {

data.setEL(KeyConstants._urltoken, pc.getURLToken());
try {
if (pc.getConfig().debug()) data.setEL("debugger", pc.getDebugger().getDebuggingData(pc));
if (PageContextUtil.debug(pc)) data.setEL("debugger", pc.getDebugger().getDebuggingData(pc));
}
catch (PageException e2) {
}
Expand Down
13 changes: 7 additions & 6 deletions core/src/main/java/lucee/runtime/ComponentPageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import lucee.runtime.type.util.ListUtil;
import lucee.runtime.type.util.StructUtil;
import lucee.runtime.type.util.UDFUtil;
import lucee.runtime.util.PageContextUtil;

/**
* A Page that can produce Components
Expand Down Expand Up @@ -174,7 +175,7 @@ public Object call(PageContext pc) throws PageException {
// METHOD INVOCATION
String qs = ReqRspUtil.getQueryString(pc.getHttpServletRequest());

if (pc.getBasePageSource() == this.getPageSource() && pc.getConfig().debug()) pc.getDebugger().setOutput(false);
if (pc.getBasePageSource() == this.getPageSource() && PageContextUtil.show(pc)) pc.getDebugger().setOutput(false);

boolean isPost = pc.getHttpServletRequest().getMethod().equalsIgnoreCase("POST");

Expand Down Expand Up @@ -413,7 +414,7 @@ private void callRest(PageContext pc, Component component, String path, Result r

if (status == 404) {
String prefix = "no rest service for [" + path + "] found";
if (pc.getConfig().debug()) {
if (PageContextUtil.show(pc)) {
msg = prefix + " in" + addDetail;
}
else {
Expand All @@ -424,7 +425,7 @@ private void callRest(PageContext pc, Component component, String path, Result r
}
else if (status == 405) {
String prefix = "Unsupported Media Type";
if (pc.getConfig().debug()) {
if (PageContextUtil.show(pc)) {
msg = prefix + " for" + addDetail;
}
else {
Expand All @@ -435,7 +436,7 @@ else if (status == 405) {
}
else if (status == 406) {
String prefix = "Not Acceptable";
if (pc.getConfig().debug()) {
if (PageContextUtil.show(pc)) {
msg = prefix + " for" + addDetail;
}
else {
Expand Down Expand Up @@ -547,7 +548,7 @@ else if (!"body".equalsIgnoreCase(restArgSource)) {
rtn = component.callWithNamedValues(pc, methodName, args);
}
catch (PageException e) {
if (pc.getConfig().debug()) {
if (PageContextUtil.show(pc)) {
throw e;
}
else {
Expand Down Expand Up @@ -813,7 +814,7 @@ else if (Decision.isCastableToArray(args)) {
}
catch (Throwable t) {
PageException pe = Caster.toPageException(t);
if (pc.getConfig().debug()) pe.setExposeMessage(true);
if (PageContextUtil.show(pc)) pe.setExposeMessage(true);
throw pe;
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/lucee/runtime/InterfacePageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lucee.runtime.net.http.ReqRspUtil;
import lucee.runtime.op.Caster;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.util.PageContextUtil;

/**
* A Page that can produce Components
Expand Down Expand Up @@ -60,7 +61,7 @@ public Object call(PageContext pc) throws PageException {
}

String qs = ReqRspUtil.getQueryString(pc.getHttpServletRequest());
if (pc.getBasePageSource() == this.getPageSource() && pc.getConfig().debug()) pc.getDebugger().setOutput(false);
if (pc.getBasePageSource() == this.getPageSource() && PageContextUtil.debug(pc)) pc.getDebugger().setOutput(false);
boolean isPost = pc.getHttpServletRequest().getMethod().equalsIgnoreCase("POST");

// POST
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/lucee/runtime/PageContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public void release() {
execLog = null;
}

if (config.debug()) {
if (PageContextUtil.debug(this)) {
boolean skipLogThread = isChild;
if (skipLogThread && hasDebugOptions(ConfigPro.DEBUG_THREAD)) skipLogThread = false;
if (!skipLogThread && !gatewayContext) config.getDebuggerPool().store(this, debugger);
Expand Down Expand Up @@ -2765,7 +2765,7 @@ private final void execute(PageSource ps, boolean throwExcpetion, boolean onlyTo
setCFOutputOnly((short) 0);
}
if (!gatewayContext) {
if (getConfig().debug()) {
if (show()) {
try {
listener.onDebug(this);
}
Expand Down Expand Up @@ -2815,6 +2815,10 @@ public boolean hasDebugOptions(int option) {
return getApplicationContext().hasDebugOptions(option);
}

public int getDebugOptions() {
return getApplicationContext().getDebugOptions();
}

private void initallog() {
if (!isGatewayContext() && config.isMonitoringEnabled()) {
RequestMonitor[] monitors = config.getRequestMonitors();
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3932,7 +3932,10 @@ protected void setCachedAfterTimeRange(TimeSpan ts) {

@Override
public TimeSpan getCachedAfterTimeRange() {
if (this.cachedAfterTimeRange != null && this.cachedAfterTimeRange.getMillis() <= 0) this.cachedAfterTimeRange = null;
TimeSpan tmp = this.cachedAfterTimeRange;
if (tmp != null && tmp.getMillis() <= 0) {
this.cachedAfterTimeRange = null;
}
return this.cachedAfterTimeRange;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/debug/DebuggerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private ArrayList<DebugEntryTemplate> toArray() {
}

public static boolean debugQueryUsage(PageContext pageContext, QueryResult qr) {
if (pageContext.getConfig().debug() && qr instanceof Query) {
if (qr instanceof Query) {
if (((PageContextImpl) pageContext).hasDebugOptions(ConfigPro.DEBUG_QUERY_USAGE)) {
((Query) qr).enableShowQueryUsage();
return true;
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public Map<String, Map<String, List<String>>> getGenericData() {
}

public static void deprecated(PageContext pc, String key, String msg) {
if (pc.getConfig().debug()) {
if (PageContextUtil.show(pc)) {
// do we already have set?
boolean exists = false;
Map<String, Map<String, List<String>>> gd = pc.getDebugger().getGenericData();
Expand Down
18 changes: 8 additions & 10 deletions core/src/main/java/lucee/runtime/debug/DebuggerPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import lucee.runtime.config.ConfigWebPro;
import lucee.runtime.exp.PageException;
import lucee.runtime.net.http.ReqRspUtil;
import lucee.runtime.op.Duplicator;
import lucee.runtime.type.Array;
import lucee.runtime.type.ArrayImpl;
import lucee.runtime.type.Struct;
Expand All @@ -43,16 +42,15 @@ public DebuggerPool(Resource storage) {

public void store(PageContext pc, Debugger debugger) {
if (ReqRspUtil.getScriptName(pc, pc.getHttpServletRequest()).indexOf("/lucee/") == 0) return;
synchronized (queue) {
try {
queue.add((Struct) Duplicator.duplicate(debugger.getDebuggingData(pc, true), true));
}
catch (PageException e) {
}

while (queue.size() > ((ConfigWebPro) pc.getConfig()).getDebugMaxRecordsLogged())
queue.poll();
try {
queue.add(debugger.getDebuggingData(pc, true));
}
catch (PageException e) {
}

while (queue.size() > ((ConfigWebPro) pc.getConfig()).getDebugMaxRecordsLogged())
queue.poll();

}

public Array getData(PageContext pc) {
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/lucee/runtime/debug/DebuggerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ private Struct _pointOutClosuresInPersistentScopes(PageContext pc, Struct sct, S
}

public static boolean debugQueryUsage(PageContext pageContext, Query query) {
if (pageContext.getConfig().debug() && query != null) {
if (((PageContextImpl) pageContext).hasDebugOptions(ConfigPro.DEBUG_QUERY_USAGE)) {
query.enableShowQueryUsage();
return true;
}
if (((PageContextImpl) pageContext).hasDebugOptions(ConfigPro.DEBUG_QUERY_USAGE)) {
query.enableShowQueryUsage();
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import lucee.runtime.PageContext;
import lucee.runtime.debug.DebugEntry;
import lucee.runtime.util.PageContextUtil;

public class DebugExecutionLog extends ExecutionLogSupport {

Expand All @@ -35,7 +36,7 @@ protected void _init(PageContext pc, Map<String, String> arguments) {
@Override
protected void _log(int startPos, int endPos, long startTime, long endTime) {

if (!pc.getConfig().debug()) return;
if (!PageContextUtil.debug(pc)) return;

long diff = endTime - startTime;
if (unit == UNIT_MICRO) diff /= 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import lucee.runtime.PageContext;
import lucee.runtime.debug.DebuggerImpl;
import lucee.runtime.ext.function.Function;
import lucee.runtime.util.PageContextUtil;

public final class IsDebugMode implements Function {

public static boolean call(PageContext pc) {
return pc.getConfig().debug() && (DebuggerImpl.getDebugEntry(pc) != null);
return PageContextUtil.debug(pc) && (DebuggerImpl.getDebugEntry(pc) != null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ private static LoggerAndSourceData addLogger(Collection.Key name, int level, Cla

public abstract void setShowTest(boolean b);

public abstract int getDebugOptions();

public abstract boolean hasDebugOptions(int option);

public abstract void setDebugOptions(int option);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import lucee.runtime.type.UDF;
import lucee.runtime.type.scope.Application;
import lucee.runtime.type.scope.Session;
import lucee.runtime.util.PageContextUtil;

public final class ClassicAppListener extends AppListenerSupport {

Expand Down Expand Up @@ -121,7 +122,7 @@ public void onDebug(PageContext pc) throws PageException {

public static void _onDebug(PageContext pc) throws PageException {
try {
if (pc.getConfig().debug()) pc.getDebugger().writeOut(pc);
if (PageContextUtil.show(pc)) pc.getDebugger().writeOut(pc);
}
catch (IOException e) {
throw Caster.toPageException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,11 @@ public boolean hasDebugOptions(int option) {
return (debugging & option) > 0;
}

@Override
public int getDebugOptions() {
return debugging;
}

@Override
public void setDebugOptions(int option) {
if (!hasDebugOptions(option)) debugging += option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import lucee.runtime.type.util.ArrayUtil;
import lucee.runtime.type.util.KeyConstants;
import lucee.runtime.type.util.UDFUtil;
import lucee.runtime.util.PageContextUtil;

public class ModernAppListener extends AppListenerSupport {

Expand Down Expand Up @@ -266,7 +267,7 @@ private PageException handlePageException(PageContextImpl pci, Component app, Pa
else return pe;
}
else {
if (!pci.isGatewayContext() && pci.getConfig().debug()) {
if (!pci.isGatewayContext() && PageContextUtil.show(pci)) {
((DebuggerImpl) pci.getDebugger()).setAbort(ExceptionUtil.getThrowingPosition(pci, _pe));
}
goon.setValue(false);
Expand Down Expand Up @@ -394,7 +395,7 @@ private PageContextImpl createPageContext(CFMLFactory factory, Component app, St

@Override
public void onDebug(PageContext pc) throws PageException {
if (((PageContextImpl) pc).isGatewayContext() || !pc.getConfig().debug()) return;
if (((PageContextImpl) pc).isGatewayContext() || !PageContextUtil.show(pc)) return;
Component app = getComponent(pc);
if (app != null && app.contains(pc, KeyConstants._onDebug)) {
call(app, pc, KeyConstants._onDebug, new Object[] { pc.getDebugger().getDebuggingData(pc) }, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public class ModernApplicationContext extends ApplicationContextSupport {
private boolean initRestSetting;
private RestSettings restSetting;
private boolean initJavaSettings;
private boolean initJavaSettingsBefore;
private JavaSettings javaSettings;
private Object ormDatasource;
private Locale locale;
Expand Down Expand Up @@ -1311,6 +1312,12 @@ public void setShowTest(boolean b) {
showTest = b;
}

@Override
public int getDebugOptions() {
if (!initMonitor) initMonitor();
return debugging;
}

@Override
public boolean hasDebugOptions(int option) {
if (!initMonitor) initMonitor();
Expand Down Expand Up @@ -1795,12 +1802,18 @@ public void setJavaSettings(JavaSettings javaSettings) {

@Override
public JavaSettings getJavaSettings() {
initJava();
return javaSettings;

return initJava();
}

private void initJava() {
private JavaSettings initJava() {
if (!initJavaSettings) {
// PATCH to avoid cycle
if (initJavaSettingsBefore) {
return new JavaSettingsImpl();
}
initJavaSettingsBefore = true;

Object o = get(component, JAVA_SETTING, null);
if (o != null && Decision.isStruct(o)) {
try {
Expand All @@ -1812,7 +1825,9 @@ private void initJava() {

}
initJavaSettings = true;
initJavaSettingsBefore = false;
}
return javaSettings;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import lucee.runtime.op.Caster;
import lucee.runtime.type.scope.Application;
import lucee.runtime.type.scope.Session;
import lucee.runtime.util.PageContextUtil;

public final class NoneAppListener extends AppListenerSupport {

Expand Down Expand Up @@ -76,7 +77,7 @@ public void onSessionEnd(CFMLFactory cfmlFactory, String applicationName, String
@Override
public void onDebug(PageContext pc) throws PageException {
try {
if (pc.getConfig().debug()) pc.getDebugger().writeOut(pc);
if (PageContextUtil.show(pc)) pc.getDebugger().writeOut(pc);
}
catch (IOException e) {
throw Caster.toPageException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import lucee.runtime.listener.RequestListener;
import lucee.runtime.type.Struct;
import lucee.runtime.type.util.ListUtil;
import lucee.runtime.util.PageContextUtil;

public class RestRequestListener implements RequestListener {

Expand Down Expand Up @@ -74,7 +75,7 @@ public PageSource execute(PageContext pc, PageSource requestedPage) throws PageE
else addDetail = " in the matching mapping [" + mapping.getVirtual() + "] at [" + mapping.getPhysical().getAbsolutePath() + "], available targets are ["
+ ListUtil.listToListEL(sources, ", ") + "]";

if (pc.getConfig().debug()) {
if (PageContextUtil.show(pc)) {
RestUtil.setStatus(pc, 404, HTMLEntities.escapeHTML(msg + addDetail));

}
Expand Down
Loading

0 comments on commit 4ee2465

Please sign in to comment.