# Patching DRSA

## Patching DRSA
#### Langkah-langkah yang dilaksanakan untuk patching
1. Backup terlebih dahulu database server sedia ada (10.29.217.31)
```
mysqldump -u root -p mampu > mampu-20250702.sql
```
2. Drop table berkaitan frontend 
```
mysql -u root -p
```
```
DROP TABLE frontend_content
```
```
DROP TABLE frontend_content_assign
```
```
DROP TABLE frontend_page
```

3. Import semula SQL dari server dev (frontend.sql)
```
mysql -u root -p mampu < frontend.sql
```
4. Adjust setting NGINX untuk mengeluarkan nonce-requestid header server-app  (10.29.217.162)


    4.1 Edit file conf 

    ```
    vim /etc/nginx/drsa.conf 
    ```

    4.2 Masukan code add header

    ```
    proxy_set_header X-Request-ID $request_id;
    
    add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'nonce-$request_id'; style-src 'self' 'nonce-$request_id';";
    
    
    ```
    
    Contoh:
    ```
    server {
    listen 80;
    server_name example.com;

    location / {
    	
        # Add CSP header with nonce
        proxy_set_header X-Request-ID $request_id;
        
        add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'nonce-$request_id'; style-src 'self' 'nonce-$request_id';";
            # Other configurations...
            root /var/www/html;
            index index.html;
        }
    }
    ```
	4.5 Restart nginx
    
    ```
    sudo service restart nginx
    ```
    
5. Panggil nonce dari php 
   
```
<?php
$nonce = $_SERVER['HTTP_X_REQUEST_ID'];
?>
<script nonce="<?php echo $nonce; ?>">
    console.log('Script with nonce');
</script>
```