-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add External Source (and External Event) Attribute Validation #116
base: develop
Are you sure you want to change the base?
Conversation
…eateExternalEventType
} catch (e) { | ||
logger.error(`POST /uploadExternalEventType: ${(e as Error).message}`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalEventType: ${(e as Error).message}`); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
Exception text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the problem, we need to ensure that any error messages sent in the response are properly sanitized or escaped to prevent XSS attacks. The best way to fix this is to use a library like he
(HTML entities) to encode the error messages before sending them in the response.
- Install the
he
library to handle HTML entity encoding. - Import the
he
library in the file. - Use the
he.encode
function to encode the error messages before sending them in the response.
-
Copy modified line R8 -
Copy modified lines R42-R43 -
Copy modified line R45 -
Copy modified lines R55-R56 -
Copy modified line R58
@@ -7,2 +7,3 @@ | ||
import { HasuraError } from '../../types/hasura.js'; | ||
import he from 'he'; | ||
|
||
@@ -40,5 +41,6 @@ | ||
} catch (e) { | ||
logger.error(`POST /uploadExternalEventType: ${(e as Error).message}`); | ||
const errorMessage = he.encode((e as Error).message); | ||
logger.error(`POST /uploadExternalEventType: ${errorMessage}`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalEventType: ${(e as Error).message}`); | ||
res.send(`POST /uploadExternalEventType: ${errorMessage}`); | ||
return; | ||
@@ -52,5 +54,6 @@ | ||
} catch (e) { | ||
logger.error(`POST /uploadExternalEventType: ${(e as Error).message}`); | ||
const errorMessage = he.encode((e as Error).message); | ||
logger.error(`POST /uploadExternalEventType: ${errorMessage}`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalEventType: ${(e as Error).message}`); | ||
res.send(`POST /uploadExternalEventType: ${errorMessage}`); | ||
return; |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
} catch (e) { | ||
logger.error(`POST /uploadExternalSourceType: ${(e as Error).message}`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalSourceType: ${(e as Error).message}`); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
Exception text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the problem, we need to ensure that any error messages sent back in the response are properly sanitized to prevent XSS attacks. The best way to achieve this is by using a library that provides HTML escaping functionality. One such library is he
(HTML entities), which can be used to escape any potentially dangerous characters in the error message.
- Install the
he
library to handle HTML escaping. - Import the
he
library in the file. - Use the
he.escape
function to sanitize the error message before sending it in the response.
-
Copy modified line R2 -
Copy modified line R53 -
Copy modified line R67
@@ -1,2 +1,3 @@ | ||
import type { Express, Request, Response } from 'express'; | ||
import he from 'he'; | ||
import type { DerivationGroupInsertInput, ExternalSourceInsertInput, ExternalSourceTypeInsertInput } from '../../types/external-source.js'; | ||
@@ -51,3 +52,3 @@ | ||
res.status(500); | ||
res.send(`POST /uploadExternalSourceType: ${(e as Error).message}`); | ||
res.send(`POST /uploadExternalSourceType: ${he.escape((e as Error).message)}`); | ||
return; | ||
@@ -65,3 +66,3 @@ | ||
res.status(500); | ||
res.send(`POST /uploadExternalSourceType: ${(e as Error).message}`); | ||
res.send(`POST /uploadExternalSourceType: ${he.escape((e as Error).message)}`); | ||
return; |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
} else { | ||
logger.error(`POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
JSON schema validation error
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the problem, we need to ensure that any user-controlled input included in the error message is properly escaped before being sent in the response. This can be achieved by using a library like he
(HTML entities) to encode the error message, preventing any HTML or JavaScript from being executed.
- Install the
he
library to handle HTML entity encoding. - Import the
he
library in the file. - Use the
he.encode
function to encode the error message before sending it in the response.
-
Copy modified line R10 -
Copy modified lines R130-R131 -
Copy modified line R133
@@ -9,2 +9,3 @@ | ||
import { HasuraError } from '../../types/hasura.js'; | ||
import he from 'he'; | ||
|
||
@@ -128,5 +129,6 @@ | ||
} else { | ||
logger.error(`POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`); | ||
const errorMessage = `POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`; | ||
logger.error(errorMessage); | ||
res.status(500); | ||
res.send(`POST /uploadExternalSource: Source's formatting is invalid per basic schema validation:\n${JSON.stringify(compiledExternalSourceSchema.errors)}`); | ||
res.send(he.encode(errorMessage)); | ||
return; |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
// source type does not exist! | ||
logger.error(`POST /uploadExternalSource: Source type ${source_type_name} does not exist!`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalSource: Source type ${source_type_name} does not exist!`); |
Check failure
Code scanning / CodeQL
Reflected cross-site scripting High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the reflected cross-site scripting vulnerability, we need to sanitize the user input before including it in the response. The best way to achieve this is by using a library that provides HTML escaping functionality. In this case, we can use the escape-html
library to escape the source_type_name
before including it in the response.
- Import the
escape-html
library. - Use the
escape
function from theescape-html
library to sanitize thesource_type_name
before including it in the response.
-
Copy modified line R2 -
Copy modified line R161 -
Copy modified line R163
@@ -1,2 +1,3 @@ | ||
import type { Express, Request, Response } from 'express'; | ||
import escape from 'escape-html'; | ||
import type { DerivationGroupInsertInput, ExternalSourceInsertInput, ExternalSourceTypeInsertInput } from '../../types/external-source.js'; | ||
@@ -159,5 +160,5 @@ | ||
// source type does not exist! | ||
logger.error(`POST /uploadExternalSource: Source type ${source_type_name} does not exist!`); | ||
logger.error(`POST /uploadExternalSource: Source type ${escape(source_type_name)} does not exist!`); | ||
res.status(500); | ||
res.send(`POST /uploadExternalSource: Source type ${source_type_name} does not exist!`); | ||
res.send(`POST /uploadExternalSource: Source type ${escape(source_type_name)} does not exist!`); | ||
return; |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"escape-html": "^1.0.3" | ||
}, |
Package | Version | Security advisories |
escape-html (npm) | 1.0.3 | None |
logger.error(`POST /uploadExternalSource: Source's attributes are invalid`); | ||
res.status(500); | ||
if (sourceSchema !== undefined) { | ||
res.send(`POST /uploadExternalSource: Source's attributes are invalid:\n${JSON.stringify(sourceSchema.errors)}`); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
JSON schema validation error
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the problem, we need to ensure that any error messages sent back in the response are properly sanitized or escaped to prevent XSS attacks. The best way to fix this is to use a library like he
(HTML entities) to escape any potentially dangerous characters in the error message before sending it back in the response.
- Install the
he
library to handle HTML entity encoding. - Import the
he
library in the file. - Use the
he.encode
function to escape the error message before sending it in the response.
-
Copy modified line R10 -
Copy modified line R174
@@ -9,2 +9,3 @@ | ||
import { HasuraError } from '../../types/hasura.js'; | ||
import he from 'he'; | ||
|
||
@@ -172,3 +173,3 @@ | ||
if (sourceSchema !== undefined) { | ||
res.send(`POST /uploadExternalSource: Source's attributes are invalid:\n${JSON.stringify(sourceSchema.errors)}`); | ||
res.send(`POST /uploadExternalSource: Source's attributes are invalid:\n${he.encode(JSON.stringify(sourceSchema.errors))}`); | ||
} else { |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
} catch (e) { | ||
logger.error(`POST /uploadExternalSource: ${(e as Error).message}`); | ||
res.status(500); | ||
res.send((e as Error).message); |
Check failure
Code scanning / CodeQL
Reflected cross-site scripting High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the reflected cross-site scripting vulnerability, we need to ensure that any user-provided data included in the error message is properly sanitized before being sent in the HTTP response. The best way to achieve this is by using a library like escape-html
to escape any potentially dangerous characters in the error message.
- Import the
escape-html
library at the top of the file. - Use the
escape
function from theescape-html
library to sanitize the error message before sending it in the response.
-
Copy modified line R2 -
Copy modified line R225
@@ -1,2 +1,3 @@ | ||
import type { Express, Request, Response } from 'express'; | ||
import escape from 'escape-html'; | ||
import type { DerivationGroupInsertInput, ExternalSourceInsertInput, ExternalSourceTypeInsertInput } from '../../types/external-source.js'; | ||
@@ -223,3 +224,3 @@ | ||
res.status(500); | ||
res.send((e as Error).message); | ||
res.send(escape((e as Error).message)); | ||
return; |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"escape-html": "^1.0.3" | ||
}, |
Package | Version | Security advisories |
escape-html (npm) | 1.0.3 | None |
} catch (e) { | ||
logger.error(`POST /uploadExternalSource: ${(e as Error).message}`); | ||
res.status(500); | ||
res.send((e as Error).message); |
Check warning
Code scanning / CodeQL
Exception text reinterpreted as HTML Medium
Exception text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the problem, we need to ensure that the error message is properly sanitized before being sent back in the response. This can be achieved by using a library like he
(HTML entities) to escape any HTML meta-characters in the error message. This will prevent any malicious scripts from being executed in the user's browser.
- Install the
he
library to handle HTML entity encoding. - Import the
he
library in the file. - Use the
he.encode
function to sanitize the error message before sending it in the response.
-
Copy modified line R10 -
Copy modified lines R223-R224 -
Copy modified line R226
@@ -9,2 +9,3 @@ | ||
import { HasuraError } from '../../types/hasura.js'; | ||
import he from 'he'; | ||
|
||
@@ -221,5 +222,6 @@ | ||
} catch (e) { | ||
logger.error(`POST /uploadExternalSource: ${(e as Error).message}`); | ||
const sanitizedMessage = he.encode((e as Error).message); | ||
logger.error(`POST /uploadExternalSource: ${sanitizedMessage}`); | ||
res.status(500); | ||
res.send((e as Error).message); | ||
res.send(sanitizedMessage); | ||
return; |
-
Copy modified lines R44-R45
@@ -43,3 +43,4 @@ | ||
"swagger-ui-express": "^4.6.3", | ||
"winston": "^3.9.0" | ||
"winston": "^3.9.0", | ||
"he": "^1.2.0" | ||
}, |
Package | Version | Security advisories |
he (npm) | 1.2.0 | None |
This pull request adds external source/event attribute validation to Aerie.
This means that when an external source is uploaded to AERIE, via endpoints like the CLI or the UI, it is forwarded here, has its formatting checked against a schema, and additionally has the attributes of the source and each of its events checked for validity, before submitting it to the database.
Submission of event/source type schemas for the purpose of later validation is also handled here - the gateway simply checks that they are valid JSON Schema.
A more thorough explanation of the feature can be found in the AERIE PR, here.