Skip to content

Commit aa9b059

Browse files
committed
Change validation for gemini.health
Add loggedOutIndicator as alternative Change attackFields validation for name & value Remove csrf property name from zap setAuthenticationMethod post data
1 parent b6abf90 commit aa9b059

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/api/app/do/sut.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internals.sutSchema = Joi.object({
3636
port: Joi.number().port().required(),
3737
browser: Joi.string().valid(...internals.configSchemaProps.sut._cvtProperties.browser.format).lowercase().default(config.get('sut.browser')), // eslint-disable-line no-underscore-dangle
3838
loggedInIndicator: Joi.string(),
39+
loggedOutIndicator: Joi.string(),
3940
context: Joi.object({ // Zap context
4041
iD: Joi.number().integer().positive(),
4142
name: Joi.string().token()
@@ -69,8 +70,8 @@ internals.sutSchema = Joi.object({
6970
id: Joi.string().min(2).regex(/^\/[-\w/]{1,200}$/).required(),
7071
attributes: Joi.object({
7172
attackFields: Joi.array().items(Joi.object({
72-
name: Joi.string().min(2).regex(/^[a-z0-9_-]+/i).required(),
73-
value: Joi.string().empty('').default(''),
73+
name: Joi.string().min(1).max(100).regex(/^[a-z0-9._-]+/i).required(),
74+
value: [Joi.string().empty('').default(''), Joi.boolean(), Joi.number()],
7475
visible: Joi.boolean()
7576
})),
7677
method: Joi.string().valid(...internals.configSchemaProps.sut._cvtProperties.method.format).uppercase().default(config.get('sut.method')), // eslint-disable-line no-underscore-dangle

src/steps/app_scan_steps.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,17 @@ Given('the application is spidered for each appScanner resourceObject', async fu
9696
const {
9797
authentication: { route: loginRoute, usernameFieldLocater, passwordFieldLocater },
9898
loggedInIndicator,
99+
loggedOutIndicator,
99100
testSession: { id: testSessionId, attributes: { username, password }, relationships: { data: testSessionResourceIdentifiers } },
100101
context: { name: contextName }
101-
} = this.sut.getProperties(['authentication', 'loggedInIndicator', 'testSession', 'context']);
102+
} = this.sut.getProperties(['authentication', 'loggedInIndicator', 'loggedOutIndicator', 'testSession', 'context']);
102103
const { percentEncode } = this.sut.getBrowser();
103104

105+
const loggedInOutIndicator = {
106+
command: loggedInIndicator ? 'setLoggedInIndicator' : 'setLoggedOutIndicator',
107+
value: loggedInIndicator || loggedOutIndicator
108+
};
109+
104110
const { maxDepth, threadCount, maxChildren } = this.zap.getProperties('spider');
105111
const zaproxy = this.zap.getZaproxy();
106112
const enabled = true;
@@ -134,15 +140,13 @@ Given('the application is spidered for each appScanner resourceObject', async fu
134140
});
135141
}, []);
136142

137-
// Only the 'userName' onwards must be URL encoded. URL encoding entire line doesn't work.
138-
// https://github.com/zaproxy/zaproxy/wiki/FAQformauth
139-
await zaproxy.authentication.setAuthenticationMethod(contextId, authenticationMethod, `loginUrl=${sutBaseUrl}${loginRoute}&loginRequestData=${usernameFieldLocater}%3D%7B%25username%25%7D%26${passwordFieldLocater}%3D%7B%25password%25%7D%26_csrf%3D`)
143+
// Only the 'userName' onwards must be URL encoded. URL encoding entire line doesn't (or at least didn't used to) work.
144+
await zaproxy.authentication.setAuthenticationMethod(contextId, authenticationMethod, `loginUrl=${sutBaseUrl}${loginRoute}&loginRequestData=${usernameFieldLocater}%3D%7B%25username%25%7D%26${passwordFieldLocater}%3D%7B%25password%25%7D`)
140145
.then(
141146
(resp) => this.publisher.pubLog({ testSessionId, logLevel: 'info', textData: `Set authentication method to "${authenticationMethod}", for Test Session with id: "${testSessionId}". Response was: ${JSON.stringify(resp)}.`, tagObj: { tags: [`pid-${process.pid}`, 'app_scan_steps'] } }),
142147
(err) => `Error occurred while attempting to set authentication method to "${authenticationMethod}", for Test Session with id: "${testSessionId}". Error was: ${err.message}.`
143148
);
144-
// https://github.com/zaproxy/zap-core-help/wiki/HelpStartConceptsAuthentication
145-
await zaproxy.authentication.setLoggedInIndicator(contextId, loggedInIndicator)
149+
await zaproxy.authentication[loggedInOutIndicator.command](contextId, loggedInOutIndicator.value)
146150
.then(
147151
(resp) => this.publisher.pubLog({ testSessionId, logLevel: 'info', textData: `Set logged in indicator "${loggedInIndicator}", for Test Session with id: "${testSessionId}". Response was: ${JSON.stringify(resp)}.`, tagObj: { tags: [`pid-${process.pid}`, 'app_scan_steps'] } }),
148152
(err) => `Error occurred while attempting to set logged in indicator to "${loggedInIndicator}", for test session with id: "${testSessionId}". Error was: ${err.message}.`
@@ -164,7 +168,7 @@ Given('the application is spidered for each appScanner resourceObject', async fu
164168
(resp) => this.publisher.pubLog({ testSessionId, logLevel: 'info', textData: `Set forced user with Id "${internals.userId}", for Test Session with id: "${testSessionId}". Response was: ${JSON.stringify(resp)}.`, tagObj: { tags: [`pid-${process.pid}`, 'app_scan_steps'] } }),
165169
(err) => `Error occurred while attempting to set forced user "${internals.userId}", for Test Session with id: "${testSessionId}". Error was: ${err.message}.`
166170
);
167-
await zaproxy.users.setAuthenticationCredentials(contextId, internals.userId, `username=${username}&password=${percentEncode(password)}`)
171+
await zaproxy.users.setAuthenticationCredentials(contextId, internals.userId, `username=${percentEncode(username)}&password=${percentEncode(password)}`)
168172
.then(
169173
(resp) => this.publisher.pubLog({ testSessionId, logLevel: 'info', textData: `Set authentication credentials, for Test Session with id: "${testSessionId}". Response was: ${JSON.stringify(resp)}.`, tagObj: { tags: [`pid-${process.pid}`, 'app_scan_steps'] } }),
170174
(err) => `Error occurred while attempting to set authentication credentials, for Test Session with id: "${testSessionId}". Error was: ${err.message}.`

0 commit comments

Comments
 (0)