Mathew Magante
Mathew Magante

Reputation: 1407

how to hide URL in a link button in laravel

I am using laravel 5.4 and I have a code like this

<td class="fit">
  <a href="{{url('addApprovalRequestor/'.$approval_requestor_id.'/'.$user->id)}}" 
     class="btn btn-primary btn-sm">Add
  </a>
</td>

Google Chrome Inspect Element

enter image description here

My View

enter image description here I feel I am not safe using that code, its there's a way how to hide url of code with out using href or form in laravel

Upvotes: 2

Views: 5238

Answers (3)

Rishabh Kushwaha
Rishabh Kushwaha

Reputation: 439

Well i totally agree with @Erkan Özkök and @lofihelsinki ,but still if you want it not to be inspect by chrome inspect you could try disabling the right click button.

Here is the help snippet-

<html>
<head>
<script type="text/javascript">
    if (document.addEventListener) { // IE >= 9; other browsers
        document.addEventListener('contextmenu', function(e) {
            
            e.preventDefault();
        }, false);
    } else { // IE < 9
        document.attachEvent('oncontextmenu', function() {
            alert("You've tried to open context menu");
            window.event.returnValue = false;
        });
    }
</script>
</head>
<body>
Lorem ipsum...
</body>
</html>

Upvotes: 3

menaka
menaka

Reputation: 1068

What is on the browser-end can be always exploited.

One way of doing this is pass the value to javascript and make a click event like this =>

<a href="#" 
     class="btn btn-primary btn-sm" onclick="go_to_link(event)">Add
  </a>

In javascript =>

let link = {{url('addApprovalRequestor/'.$approval_requestor_id.'/'.$user- >id)}};

function show_more_menu(e) {
    e.preventDefault();
    window.location = link;
 }

But again there is no way to hide the javascript code. JS-Scripts are running inside your browser.To avoid this also, you can try to compress them, to avoid to easy reading by user. => here

Also you can disable all the bellow actions.

  • Right Click
  • F12
  • Ctrl + Shift + I
  • Ctrl + Shift + J
  • Ctrl + Shift + C
  • Ctrl + U

    <body oncontextmenu="return false;">

     document.onkeydown = function(e) {
    
      if(event.keyCode == 123) {
         return false;
      }
      if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
         return false;
      }
      if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
         return false;
      }
      if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
         return false;
      }
      if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
         return false;
      }
    }
    

Upvotes: 2

Afraz Ahmad
Afraz Ahmad

Reputation: 5386

Answer to your question is POST request

Route:

change your route type from GET to POST

Route::post('/addApprovalRequestor','controllerName@methodName');

Blade

Use form with post request then url will be hidden

<form action="{{url('/addApprovalRequestor')}}" method="post">
     {{csrf_field()}}
     //save values in hidden input and this form will send it to server
     <input type="hidden" name="approval_requester_id" value="{{$approval_requester_id}}">
     <input type="hidden" name="user_id" value="{{$user->id}}">
   <button type="submit">submit</button>
</form>

Controller

function methodName(Request $request){
   dd($request->request);
   //do what you want here
}

Upvotes: 3

Related Questions