Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
fix: Fixes to scanners
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilpin committed Oct 12, 2021
1 parent fd3f80e commit b1a264a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/analyzer/recordSecrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Event } from '@appland/models';
import { emptyValue, verbose } from '../scanner/util';

export default function (secrets: Set<string>, e: Event): void {
if (!e.returnValue) {
return;
}
if (emptyValue(e.returnValue.value)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sampleConfig/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const assertions: Assertion[] = [
slowQuery.scanner(new slowQuery.Options(0.05)),
queryFromView.scanner(),
missingContentType.scanner(),
missingAuthentication.scanner(),
missingAuthentication.scanner(new missingAuthentication.Options([/\/api\//])),
validateBeforeSave.scanner(),
leafExpected.scanner('http_client_request'),
leafExpected.scanner('sql_query'),
Expand Down
2 changes: 1 addition & 1 deletion src/sampleConfig/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ scanners:
- id: missingContentType
- id: missingAuthentication
properties:
routes: [ /.*/ ]
routes: [ /\/api\// ]
- id: validateBeforeSave
- id: secretInLog
1 change: 1 addition & 0 deletions src/sampleConfig/railsSampleApp6thEd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ scanners:
timeAllowed: 0.05
- id: missingContentType
- id: missingAuthentication
- id: insecureCompare
- id: secretInLog
- id: updateInGetRequest
17 changes: 17 additions & 0 deletions src/sampleConfig/solidus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
scanners:
- id: slowHttpServerRequest
properties:
timeAllowed: 1.0
- id: slowQuery
properties:
timeAllowed: 0.25
- id: missingContentType
- id: missingAuthentication
properties:
routes:
- /\/api/\/
- id: secretInLog
- id: updateInGetRequest
properties:
query_exclude:
- /^INSERT INTO "spree_order_mutexes"/
4 changes: 2 additions & 2 deletions src/scanner/missingContentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Assertion from '../assertion';
import { contentType } from './util';

const isRedirect = (status: number) => [301, 302, 303, 307, 308].includes(status);
const isNoContent = (status: number) => status != 204;
const hasContent = (status: number) => status !== 204;

const scanner = (): Assertion => {
return Assertion.assert(
Expand All @@ -15,7 +15,7 @@ const scanner = (): Assertion => {
assertion.where = (e: Event) =>
e.httpServerResponse !== undefined &&
!isRedirect(e.httpServerResponse!.status) &&
!isNoContent(e.httpServerResponse!.status);
hasContent(e.httpServerResponse!.status);
assertion.description = `HTTP server request must have a Content-Type header`;
}
);
Expand Down
5 changes: 4 additions & 1 deletion src/scanner/updateInGetRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ class Options {
private _queryInclude: RegExp[];
private _queryExclude: RegExp[];

constructor(queryInclude: RegExp[] = [/INSERT/i, /UPDATE/i], queryExclude: RegExp[] = []) {
constructor(
queryInclude: RegExp[] = [/\binsert\b/i, /\bupdate\b/i],
queryExclude: RegExp[] = []
) {
this._queryInclude = queryInclude;
this._queryExclude = queryExclude;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@
},
{
"event": "return",
"http_server_response": { "mime_type": "text/html;charset=UTF-8", "status": 200 },
"http_server_response": {
"status": 200,
"headers": {
"Content-Type": "text/html;charset=UTF-8"
}
},
"id": 1049,
"parent_id": 1037,
"thread_id": 1
Expand Down

0 comments on commit b1a264a

Please sign in to comment.