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

fix: vulnerability email #256

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add app logic
tangimds committed Jan 21, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d0dcd9d4bafeafaddf1aa8c98839b1580fb0ffdd
2 changes: 1 addition & 1 deletion api/src/config.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ const DATABASE_URL = process.env.DATABASE_URL;
const CRONJOBS_ENABLED = process.env.CRONJOBS_ENABLED === "true";

const PUSH_NOTIFICATION_GCM_ID = process.env.PUSH_NOTIFICATION_GCM_ID;
const PUSH_NOTIFICATION_APN_KEY = process.env.PUSH_NOTIFICATION_APN_KEY.replace(/\\n/g, "\n");
const PUSH_NOTIFICATION_APN_KEY = process.env.PUSH_NOTIFICATION_APN_KEY?.replace(/\\n/g, "\n");
const PUSH_NOTIFICATION_APN_KEY_ID = process.env.PUSH_NOTIFICATION_APN_KEY_ID;
const PUSH_NOTIFICATION_APN_TEAM_ID = process.env.PUSH_NOTIFICATION_APN_TEAM_ID;

14 changes: 4 additions & 10 deletions app/eas.json
Original file line number Diff line number Diff line change
@@ -9,30 +9,24 @@
"distribution": "internal",
"env": {
"EXPO_PUBLIC_SCHEME": "http",
"EXPO_PUBLIC_HOST": "localhost",
"EXPO_PUBLIC_APP_ENV": "development",
"EXPO_PUBLIC_TIPIMAIL_API_KEY": "1234567890",
"EXPO_PUBLIC_TIPIMAIL_API_USER": "1234567890"
"EXPO_PUBLIC_HOST": "localhost:3000",
"EXPO_PUBLIC_APP_ENV": "development"
}
},
"preview": {
"distribution": "internal",
"env": {
"EXPO_PUBLIC_SCHEME": "https",
"EXPO_PUBLIC_HOST": "api-monsuivipsy.fabrique.social.gouv.fr",
"EXPO_PUBLIC_APP_ENV": "production",
"EXPO_PUBLIC_TIPIMAIL_API_KEY": "1234567890",
"EXPO_PUBLIC_TIPIMAIL_API_USER": "1234567890"
"EXPO_PUBLIC_APP_ENV": "production"
}
},
"production": {
"autoIncrement": true,
"env": {
"EXPO_PUBLIC_SCHEME": "https",
"EXPO_PUBLIC_HOST": "api-monsuivipsy.fabrique.social.gouv.fr",
"EXPO_PUBLIC_APP_ENV": "production",
"EXPO_PUBLIC_TIPIMAIL_API_KEY": "1234567890",
"EXPO_PUBLIC_TIPIMAIL_API_USER": "1234567890"
"EXPO_PUBLIC_APP_ENV": "production"
},
"android": {
"credentialsSource": "local"
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
"@react-navigation/material-top-tabs": "^6.6.14",
"@react-navigation/native": "^6.1.18",
"@react-navigation/stack": "^6.4.1",
"crypto-js": "^4.2.0",
"csv-parser": "^3.0.0",
"date-fns": "^2.16.1",
"dayjs": "^1.11.3",
9 changes: 3 additions & 6 deletions app/src/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// import envConfig from "react-native-config";
import {version, buildNumber} from '../package.json';

// const SCHEME = envConfig.SCHEME;
// const HOST = envConfig.HOST;
// const APP_ENV = envConfig.APP_ENV;
const SCHEME = process.env.EXPO_PUBLIC_SCHEME;
const HOST = process.env.EXPO_PUBLIC_HOST;
const APP_ENV = process.env.EXPO_PUBLIC_APP_ENV;
const VERSION = version;
const BUILD_NUMBER = buildNumber;
// const TIPIMAIL_API_KEY = envConfig.TIPIMAIL_API_KEY;
// const TIPIMAIL_API_USER = envConfig.TIPIMAIL_API_USER;

export {SCHEME, HOST, APP_ENV, VERSION, BUILD_NUMBER};
const HMAC_SECRET = process.env.EXPO_PUBLIC_HMAC_SECRET;

export {SCHEME, HOST, APP_ENV, VERSION, BUILD_NUMBER, HMAC_SECRET};
47 changes: 28 additions & 19 deletions app/src/services/api.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import URI from "urijs";
import { Alert, Linking, Platform } from "react-native";
import NetInfo from "@react-native-community/netinfo";
import fetchRetry from "fetch-retry";
import URI from 'urijs';
import {Alert, Linking, Platform} from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import fetchRetry from 'fetch-retry';

import { SCHEME, HOST, BUILD_NUMBER } from "../config";
import matomo from "./matomo";
import {SCHEME, HOST, BUILD_NUMBER} from '../config';
import matomo from './matomo';
import {generateHMAC} from '../utils/generateHmac';

export const checkNetwork = async (test = false) => {
const isConnected = await NetInfo.fetch().then((state) => state.isConnected);
const isConnected = await NetInfo.fetch().then(state => state.isConnected);
if (!isConnected || test) {
await new Promise((res) => setTimeout(res, 1500));
Alert.alert("Pas de réseau", "Veuillez vérifier votre connexion");
await new Promise(res => setTimeout(res, 1500));
Alert.alert('Pas de réseau', 'Veuillez vérifier votre connexion');
return false;
}
return true;
@@ -23,13 +24,21 @@ class ApiService {
getUrl = (path, query) => {
return new URI().host(this.host).scheme(this.scheme).path(path).setSearch(query).toString();
};
execute = async ({ method = "GET", path = "", query = {}, headers = {}, body = null }) => {
execute = async ({method = 'GET', path = '', query = {}, headers = {}, body = null}) => {
try {
if (body) {
const {signature, timestamp} = generateHMAC(body);
headers = {
...headers,
'x-signature': signature,
'x-timestamp': timestamp,
};
}
const config = {
method,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
'Content-Type': 'application/json',
Accept: 'application/json',
appversion: BUILD_NUMBER,
appdevice: Platform.OS,
currentroute: this.navigation?.getCurrentRoute?.()?.name,
@@ -41,7 +50,7 @@ class ApiService {
};

const url = this.getUrl(path, query);
console.log("api: ", { url });
// console.log('api: ', {url});
const canFetch = await checkNetwork();
if (!canFetch) return;

@@ -65,15 +74,15 @@ class ApiService {

needUpdate = false;

get = async (args) => this.execute({ method: "GET", ...args });
post = async (args) => this.execute({ method: "POST", ...args });
put = async (args) => this.execute({ method: "PUT", ...args });
delete = async (args) => this.execute({ method: "DELETE", ...args });
get = async args => this.execute({method: 'GET', ...args});
post = async args => this.execute({method: 'POST', ...args});
put = async args => this.execute({method: 'PUT', ...args});
delete = async args => this.execute({method: 'DELETE', ...args});

handleInAppMessage = (inAppMessage) => {
handleInAppMessage = inAppMessage => {
const [title, subTitle, actions = [], options = {}] = inAppMessage;
if (!actions || !actions.length) return Alert.alert(title, subTitle);
const actionsWithNavigation = actions.map((action) => {
const actionsWithNavigation = actions.map(action => {
if (action.navigate) {
action.onPress = () => {
API.navigation.navigate(...action.navigate);
10 changes: 10 additions & 0 deletions app/src/utils/generateHmac.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import crypto from "crypto-js";
import { HMAC_SECRET } from "../config";

export const generateHMAC = (payload) => {
const timestamp = Date.now().toString();
const dataToSign = `${timestamp}:${JSON.stringify(payload)}`;
const signature = crypto.HmacSHA256(dataToSign, HMAC_SECRET).toString();

return { signature, timestamp };
};
1,492 changes: 329 additions & 1,163 deletions app/yarn.lock

Large diffs are not rendered by default.