Skip to content
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

feat: Improve Application Security #1889

Merged
merged 20 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ You can also check the
# Unreleased

- Features
- Implemented Content Security Policy (CSP)
- It's now possible to export charts as images
- Added Footer to the Profile Page
- Fixes
- Addressed security flaw allowing the injection of arbitrary URLs
in the `sourceUrl` parameter in the GraphQL API
- Color mapping is now correctly kept up to date in case of editing an old
chart and the cube has been updated in the meantime and contains new values
in the color dimension
Expand Down Expand Up @@ -51,6 +54,7 @@ You can also check the
- Added auto-generated JSON Schema files for configurator state and chart
config and improved preview charts via API documentation


# [5.0.2] - 2024-11-28

- Features
Expand Down
2 changes: 2 additions & 0 deletions app/domain/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from "@/domain/datasource/constants";
import { ENDPOINT } from "@/domain/env";

export { isDataSourceUrlAllowed, type DataSourceUrl } from "./urls";

export const parseDataSource = (stringifiedSource: string): DataSource => {
const [type, url] = stringifiedSource.split("+") as [
DataSource["type"],
Expand Down
17 changes: 17 additions & 0 deletions app/domain/datasource/urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SOURCE_OPTIONS } from "@/domain/datasource/constants";

const allowedSourceLabels = JSON.parse(
process.env.WHITELISTED_DATA_SOURCES ?? "[]"
);

const allowedSources = SOURCE_OPTIONS.filter((o) =>
allowedSourceLabels.includes(o.label)
);

const allowedDataSourceUrls = allowedSources.map((o) => o.value.split("+")[1]);

export type DataSourceUrl = string & {};

export const isDataSourceUrlAllowed = (url: string): url is DataSourceUrl => {
return typeof url === "string" && allowedDataSourceUrls.includes(url);
};
18 changes: 9 additions & 9 deletions app/graphql/queries/data-cubes.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
query SearchCubes(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$query: String
$order: SearchCubeResultOrder
Expand All @@ -26,7 +26,7 @@ query SearchCubes(

query DataCubeLatestIri(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$cubeFilter: DataCubeLatestIriFilter!
) {
dataCubeLatestIri(
Expand All @@ -50,7 +50,7 @@ query DataCubeUnversionedIri(

query DataCubeComponents(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubeComponentFilter!
) {
Expand All @@ -64,7 +64,7 @@ query DataCubeComponents(

query DataCubeDimensionGeoShapes(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubeDimensionGeoShapesCubeFilter!
) {
Expand All @@ -78,7 +78,7 @@ query DataCubeDimensionGeoShapes(

query DataCubeMetadata(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubeMetadataFilter!
) {
Expand All @@ -92,7 +92,7 @@ query DataCubeMetadata(

query DataCubeComponentTermsets(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubeTermsetFilter!
) {
Expand All @@ -106,7 +106,7 @@ query DataCubeComponentTermsets(

query DataCubeObservations(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubeObservationFilter!
) {
Expand All @@ -120,7 +120,7 @@ query DataCubeObservations(

query DataCubePreview(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$locale: String!
$cubeFilter: DataCubePreviewFilter!
) {
Expand All @@ -134,7 +134,7 @@ query DataCubePreview(

query PossibleFilters(
$sourceType: String!
$sourceUrl: String!
$sourceUrl: DataSourceUrl!
$cubeFilter: DataCubePossibleFiltersCubeFilter!
) {
possibleFilters(
Expand Down
Loading
Loading