Skip to content

Commit d8221f4

Browse files
committed
Fix security issue and added categories to the log messages
1 parent 96a19d8 commit d8221f4

File tree

10 files changed

+556
-546
lines changed

10 files changed

+556
-546
lines changed

src/Blazor.Extensions.Logging.JS/package-lock.json

Lines changed: 16 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Blazor.Extensions.Logging.JS/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"dependencies": {
11-
"lodash": ">=4.17.11"
11+
"lodash": ">=4.17.13"
1212
},
1313
"devDependencies": {
1414
"@types/emscripten": "0.0.31",
1515
"ts-loader": "^4.4.2",
16-
"typescript": "^2.9.2",
16+
"typescript": "^3.5.2",
1717
"webpack": "^4.16.3",
1818
"webpack-cli": "^3.1.0"
1919
}
Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1-
import { LogObject, LogObjectType, LogLevel } from './LogObject';
2-
3-
interface IBrowserConsoleLogger {
4-
Log(logObjectValue: string): void;
5-
}
6-
7-
export class BrowserConsoleLogger implements IBrowserConsoleLogger {
8-
Log(logObjectValue: string): void {
9-
const logObject: LogObject = JSON.parse(logObjectValue);
10-
let logMethod: Function = console.log;
11-
12-
// if we've a table, we'll print it as a table anyway, it is unlikely that the developer want to log errornous data as a table.
13-
if (logObject.type === LogObjectType.Table) {
14-
logMethod = console.table;
15-
} else {
16-
switch (logObject.logLevel) {
17-
case LogLevel.Trace:
18-
logMethod = console.trace;
19-
break;
20-
case LogLevel.Debug:
21-
logMethod = console.debug;
22-
break;
23-
case LogLevel.Warning:
24-
logMethod = console.warn;
25-
break;
26-
case LogLevel.Error:
27-
case LogLevel.Critical:
28-
logMethod = console.error;
29-
break;
30-
}
31-
}
32-
33-
logMethod(logObject.payload);
34-
35-
if (logObject.exception) {
36-
logMethod("Exception: ", logObject.exception);
37-
}
38-
}
39-
}
1+
import { LogObject, LogObjectType, LogLevel } from './LogObject';
2+
3+
interface IBrowserConsoleLogger {
4+
Log(logObjectValue: string): void;
5+
}
6+
7+
export class BrowserConsoleLogger implements IBrowserConsoleLogger {
8+
Log(logObjectValue: string): void {
9+
const logObject: LogObject = JSON.parse(logObjectValue);
10+
let logMethod: Function = console.log;
11+
12+
// if we've a table, we'll print it as a table anyway, it is unlikely that the developer want to log errornous data as a table.
13+
if (logObject.Type === LogObjectType.Table) {
14+
logMethod = console.table;
15+
} else {
16+
switch (logObject.LogLevel) {
17+
case LogLevel.Trace:
18+
logMethod = console.trace;
19+
break;
20+
case LogLevel.Debug:
21+
logMethod = console.debug;
22+
break;
23+
case LogLevel.Warning:
24+
logMethod = console.warn;
25+
break;
26+
case LogLevel.Error:
27+
case LogLevel.Critical:
28+
logMethod = console.error;
29+
break;
30+
}
31+
}
32+
if (logObject.Type == LogObjectType.Table) {
33+
logMethod(logObject.Payload);
34+
} else {
35+
logMethod(`[${logObject.Category}]`, logObject.Payload);
36+
}
37+
38+
if (logObject.Exception) {
39+
logMethod(`[${logObject.Category}] Exception: `, logObject.Exception);
40+
}
41+
}
42+
}
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
export type LogObject = {
2-
logLevel: LogLevel;
3-
type: LogObjectType;
4-
payload: any;
5-
exception: string;
6-
}
7-
8-
// enum coming from Microsoft.Extensions.Logging
9-
export enum LogLevel {
10-
Trace = 0,
11-
Debug = 1,
12-
Information = 2,
13-
Warning = 3,
14-
Error = 4,
15-
Critical = 5,
16-
None = 6
17-
}
18-
19-
export enum LogObjectType {
20-
String = 0,
21-
Object = 1,
22-
Table = 2
23-
}
1+
export type LogObject = {
2+
Category: string;
3+
LogLevel: LogLevel;
4+
Type: LogObjectType;
5+
Payload: any;
6+
Exception: string;
7+
}
8+
9+
// enum coming from Microsoft.Extensions.Logging
10+
export enum LogLevel {
11+
Trace = 0,
12+
Debug = 1,
13+
Information = 2,
14+
Warning = 3,
15+
Error = 4,
16+
Critical = 5,
17+
None = 6
18+
}
19+
20+
export enum LogObjectType {
21+
String = 0,
22+
Object = 1,
23+
Table = 2
24+
}

0 commit comments

Comments
 (0)